DsFieldTemplateBase.php in Display Suite 8.4
File
src/Plugin/DsFieldTemplate/DsFieldTemplateBase.php
View source
<?php
namespace Drupal\ds\Plugin\DsFieldTemplate;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\ds\Ds;
abstract class DsFieldTemplateBase extends PluginBase implements DsFieldTemplateInterface {
protected $entity = NULL;
public function __construct($configuration, $plugin_id, $plugin_definition) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configuration += $this
->defaultConfiguration();
}
public function getEntity() {
return $this->entity;
}
public function setEntity(EntityInterface $entity) {
$this->entity = $entity;
}
public function alterForm(&$form) {
$config = $this
->getConfiguration();
$form['lb'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#size' => '10',
'#default_value' => $config['lb'],
];
$form['lb-col'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show label colon'),
'#default_value' => $config['lb-col'],
'#attributes' => [
'class' => [
'colon-checkbox',
],
],
];
$field_classes = Ds::getClasses('field');
if (!empty($field_classes)) {
$form['classes'] = [
'#type' => 'select',
'#multiple' => TRUE,
'#options' => $field_classes,
'#title' => $this
->t('Choose additional CSS classes for the field'),
'#default_value' => $config['classes'],
'#prefix' => '<div class="field-classes">',
'#suffix' => '</div>',
];
}
else {
$form['classes'] = [
'#type' => 'value',
'#value' => [],
];
}
}
public function massageRenderValues(&$field_settings, $values) {
if (!empty($values['lb'])) {
$field_settings['lb'] = $values['lb'];
}
if (!empty($values['lb-col'])) {
$field_settings['lb-col'] = TRUE;
}
if (isset($values['classes'])) {
$field_settings['classes'] = $values['classes'];
}
}
public function getThemeFunction() {
return $this->pluginDefinition['theme'];
}
public function defaultConfiguration() {
$config = [];
$config['lb'] = '';
$config['lb-col'] = \Drupal::config('ds.settings')
->get('ft-show-colon');
$config['classes'] = [];
return $config;
}
public function getConfiguration() {
return $this->configuration;
}
public function setConfiguration(array $configuration) {
$this->configuration = $configuration + $this->configuration;
}
}