Welcome block
* @property IndexPage $parent
* @copyright Tamaranga
*/
class IndexWelcomeBlock extends Block
{
/** @var string Приветствие */
public $title = '';
/** @var string Цвет */
public $color = '#ffffff';
/** @var string Цвет тени на изображении */
public $shadow_color = '#000000';
/** @var string Прозрачность тени на изображении */
public $shadow_opacity = '0.6';
/** @var string Изображение: desktop */
public $background_desktop = '';
/** @var string Изображение: phone */
public $background_phone = '';
public function init()
{
parent::init();
$this->setKey('welcome');
$this->setTitle(_t('@site', 'Greeting'));
$this->setTemplate('index/welcome', 'site');
}
public function data()
{
$data = parent::data();
$data['background'] = '';
if ($this->isPhone()) {
if (! empty($this->background_phone)) {
$data['background'] = $this->background_phone;
}
} else {
if (! empty($this->background_desktop)) {
$data['background'] = $this->background_desktop;
}
}
# Скрываем блок без фонового изображения
if (empty($data['background'])) {
return false;
}
$data['filter_view'] = $this->parent->filterView ?? '';
return $data;
}
public function settingsForm($form)
{
$form
->staticText('title', _t('@site', 'Title'), function () {
return $this->titleh1();
})->tip(Admin::crumbs([_t('@', 'SEO'), _t('@site', 'General Pages'), $this->parent->getTitle(), _t('@seo', 'Title H1')]))
->color('color', _t('@site', 'Header color'), '#ffffff')
->color('shadow_color', _t('@site', 'Background Shadow Color'), '#000000')
->select('shadow_opacity', _t('@site', 'Background Shadow Opacity'), '0.6', [
['id' => '0', 'title' => '100%'],
['id' => '0.1', 'title' => '90%'],
['id' => '0.2', 'title' => '80%'],
['id' => '0.3', 'title' => '70%'],
['id' => '0.4', 'title' => '60%'],
['id' => '0.5', 'title' => '50%'],
['id' => '0.6', 'title' => '40%'],
['id' => '0.7', 'title' => '30%'],
['id' => '0.8', 'title' => '20%'],
['id' => '0.9', 'title' => '10%'],
['id' => '1.0', 'title' => '0%'],
])
->images('background_desktop', _t('@site', 'Image'), 1)
->htmlAfter('' . _t('@site', 'Recommended size: [size]', ['size' => '1200х180']) . '')
->preload(bff::path('/static/img/default/index_background_desktop.jpg'))
->images('background_phone', _t('@site', 'Image (mobile)'), 1)
->htmlAfter('' . _t('@site', 'Recommended size: [size]', ['size' => '1200х180']) . '')
->preload(bff::path('/static/img/default/index_background_phone.jpg'))
;
}
public function titleh1(): string
{
$data = $this->parent->seo->load(false);
return $this->locale->value(
$data['titleh1'] ?? [],
$this->language
);
}
public function settings()
{
return [
'title',
'color',
'shadow_color',
'shadow_opacity',
'background_desktop',
'background_phone',
];
}
}