FlexsliderFormatterTrait.php in Flex Slider 8.2
File
flexslider_fields/src/Plugin/Field/FieldFormatter/FlexsliderFormatterTrait.php
View source
<?php
namespace Drupal\flexslider_fields\Plugin\Field\FieldFormatter;
use Drupal\Core\Url;
use Drupal\flexslider\Entity\Flexslider;
trait FlexsliderFormatterTrait {
protected static function getDefaultSettings() {
return [
'optionset' => 'default',
];
}
protected function buildSettingsSummary() {
$summary = [];
$optionset = $this
->loadOptionset($this
->getSetting('optionset'));
$os_summary = $optionset ? $optionset
->label() : $this
->t('Default settings');
$summary[] = $this
->t('Option set: %os_summary', [
'%os_summary' => $os_summary,
]);
return $summary;
}
protected function buildSettingsForm() {
$optionsets = flexslider_optionset_list();
$element['optionset'] = [
'#title' => $this
->t('Option Set'),
'#type' => 'select',
'#default_value' => $this
->getSetting('optionset'),
'#options' => $optionsets,
];
$element['links'] = [
'#theme' => 'links',
'#links' => [
[
'title' => $this
->t('Create new option set'),
'url' => Url::fromRoute('entity.flexslider.add_form', [], [
'query' => \Drupal::destination()
->getAsArray(),
]),
],
[
'title' => $this
->t('Manage option sets'),
'url' => Url::fromRoute('entity.flexslider.collection', [], [
'query' => \Drupal::destination()
->getAsArray(),
]),
],
],
'#access' => \Drupal::currentUser()
->hasPermission('administer flexslider'),
];
return $element;
}
protected function loadOptionset($id) {
return Flexslider::load($id);
}
protected function getOptionsetDependencies() {
$dependencies = [];
$option_id = $this
->getSetting('optionset');
if ($option_id && ($optionset = $this
->loadOptionset($option_id))) {
$dependencies[$optionset
->getConfigDependencyKey()][] = $optionset
->getConfigDependencyName();
}
return $dependencies;
}
protected function optionsetDependenciesDeleted(array $dependencies_deleted) {
$option_id = $this
->getSetting('optionset');
if ($option_id && ($optionset = $this
->loadOptionset($option_id))) {
if (!empty($dependencies_deleted[$optionset
->getConfigDependencyKey()]) && in_array($optionset
->getConfigDependencyName(), $dependencies_deleted[$optionset
->getConfigDependencyKey()])) {
$this
->setSetting('optionset', 'default');
return TRUE;
}
}
return FALSE;
}
}