View source
<?php
namespace Drupal\blazy_test\Form;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\blazy\Form\BlazyAdminInterface;
use Drupal\blazy\BlazyManagerInterface;
class BlazyAdminTest implements BlazyAdminTestInterface {
use StringTranslationTrait;
protected $blazyAdmin;
protected $manager;
public function __construct(BlazyAdminInterface $blazy_admin, BlazyManagerInterface $manager) {
$this->blazyAdmin = $blazy_admin;
$this->manager = $manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('blazy.admin.extended'), $container
->get('blazy.manager'));
}
public function blazyAdmin() {
return $this->blazyAdmin;
}
public function manager() {
return $this->manager;
}
public function buildSettingsForm(array &$form, $definition = []) {
$definition += [
'namespace' => 'blazy',
'optionsets' => [],
'skins' => [],
'grid_form' => TRUE,
'style' => TRUE,
];
$keys = [
'background',
'caches',
'fieldable_form',
'id',
'vanilla',
];
foreach ($keys as $key) {
$definition[$key] = TRUE;
}
$definition['layouts'] = isset($definition['layouts']) ? array_merge($this
->getLayoutOptions(), $definition['layouts']) : $this
->getLayoutOptions();
$this
->openingForm($form, $definition);
$this
->mainForm($form, $definition);
$this
->closingForm($form, $definition);
}
public function openingForm(array &$form, &$definition = []) {
$this->blazyAdmin
->openingForm($form, $definition);
}
public function mainForm(array &$form, $definition = []) {
if (!empty($definition['image_style_form'])) {
$this->blazyAdmin
->imageStyleForm($form, $definition);
}
if (!empty($definition['media_switch_form'])) {
$this->blazyAdmin
->mediaSwitchForm($form, $definition);
}
if (!empty($definition['grid_form'])) {
$this->blazyAdmin
->gridForm($form, $definition);
}
if (!empty($definition['fieldable_form'])) {
$this->blazyAdmin
->fieldableForm($form, $definition);
}
}
public function closingForm(array &$form, $definition = []) {
$this->blazyAdmin
->closingForm($form, $definition);
}
public function getLayoutOptions() {
return [
'bottom' => $this
->t('Caption bottom'),
'center' => $this
->t('Caption center'),
'top' => $this
->t('Caption top'),
];
}
public function getSettingsSummary(array $definition = []) {
return $this->blazyAdmin
->getSettingsSummary($definition);
}
public function getFieldOptions($target_bundles = [], $allowed_field_types = [], $entity_type_id = 'media', $target_type = '') {
return $this->blazyAdmin
->getFieldOptions($target_bundles, $allowed_field_types, $entity_type_id, $target_type);
}
public function finalizeForm(array &$form, $definition = []) {
$this->blazyAdmin
->finalizeForm($form, $definition);
}
}