class Expert in Display Suite 8.4
Same name and namespace in other branches
- 8.2 src/Plugin/DsFieldTemplate/Expert.php \Drupal\ds\Plugin\DsFieldTemplate\Expert
- 8.3 src/Plugin/DsFieldTemplate/Expert.php \Drupal\ds\Plugin\DsFieldTemplate\Expert
Plugin for the expert field template.
Plugin annotation
@DsFieldTemplate(
id = "expert",
title = @Translation("Expert"),
theme = "ds_field_expert",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\ds\Plugin\DsFieldTemplate\DsFieldTemplateBase implements DsFieldTemplateInterface
- class \Drupal\ds\Plugin\DsFieldTemplate\Expert
- class \Drupal\ds\Plugin\DsFieldTemplate\DsFieldTemplateBase implements DsFieldTemplateInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of Expert
File
- src/
Plugin/ DsFieldTemplate/ Expert.php, line 14
Namespace
Drupal\ds\Plugin\DsFieldTemplateView source
class Expert extends DsFieldTemplateBase {
/**
* {@inheritdoc}
*/
public function alterForm(&$form) {
$config = $this
->getConfiguration();
// Add label.
$form['lb'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#size' => '10',
'#default_value' => $config['lb'],
];
// Add prefix.
$form['prefix'] = [
'#type' => 'textfield',
'#title' => $this
->t('Prefix'),
'#size' => '100',
'#description' => $this
->t('You can enter any html in here.'),
'#default_value' => isset($config['prefix']) ? $config['prefix'] : '',
'#prefix' => '<div class="field-prefix">',
'#suffix' => '</div>',
];
$wrappers = [
'lbw' => [
'title' => $this
->t('Label wrapper'),
],
'ow' => [
'title' => $this
->t('Outer wrapper'),
],
'fis' => [
'title' => $this
->t('Field items'),
],
'fi' => [
'title' => $this
->t('Field item'),
],
];
foreach ($wrappers as $wrapper_key => $value) {
$form[$wrapper_key] = [
'#type' => 'checkbox',
'#title' => $value['title'],
'#prefix' => '<div class="ft-group ' . $wrapper_key . '">',
'#default_value' => $config[$wrapper_key],
];
$form[$wrapper_key . '-el'] = [
'#type' => 'textfield',
'#title' => $this
->t('Element'),
'#size' => '10',
'#description' => $this
->t('E.g. div, span, h2 etc.'),
'#default_value' => $config[$wrapper_key . '-el'],
'#states' => [
'visible' => [
':input[name$="[' . $wrapper_key . ']"]' => [
'checked' => TRUE,
],
],
],
];
$form[$wrapper_key . '-cl'] = [
'#type' => 'textfield',
'#title' => $this
->t('Classes'),
'#size' => '10',
'#default_value' => $config[$wrapper_key . '-cl'],
'#description' => $this
->t('E.g. field-expert'),
'#states' => [
'visible' => [
':input[name$="[' . $wrapper_key . ']"]' => [
'checked' => TRUE,
],
],
],
];
$form[$wrapper_key . '-at'] = [
'#type' => 'textfield',
'#title' => $this
->t('Attributes'),
'#size' => '20',
'#default_value' => $config[$wrapper_key . '-at'],
'#description' => $this
->t('E.g. name="anchor"'),
'#states' => [
'visible' => [
':input[name$="[' . $wrapper_key . ']"]' => [
'checked' => TRUE,
],
],
],
];
// Hide colon.
if ($wrapper_key == 'lbw') {
$form['lb-col'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Show label colon'),
'#default_value' => $config['lb-col'],
'#attributes' => [
'class' => [
'colon-checkbox',
],
],
'#states' => [
'visible' => [
':input[name$="[' . $wrapper_key . ']"]' => [
'checked' => TRUE,
],
],
],
];
}
if ($wrapper_key != 'lbw') {
$form[$wrapper_key . '-def-at'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Add default attributes'),
'#default_value' => $config[$wrapper_key . '-def-at'],
'#suffix' => $wrapper_key == 'ow' ? '' : '</div><div class="clearfix"></div>',
'#states' => [
'visible' => [
':input[name$="[' . $wrapper_key . ']"]' => [
'checked' => TRUE,
],
],
],
];
}
else {
$form['ft'][$wrapper_key . '-def-at'] = [
'#markup' => '</div><div class="clearfix"></div>',
];
}
// Default classes for outer wrapper.
if ($wrapper_key == 'ow') {
$form[$wrapper_key . '-def-cl'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Add default classes'),
'#default_value' => $config[$wrapper_key . '-def-cl'],
'#suffix' => '</div><div class="clearfix"></div>',
'#states' => [
'visible' => [
':input[name$="[' . $wrapper_key . ']"]' => [
'checked' => TRUE,
],
],
],
];
}
}
// Add suffix.
$form['suffix'] = [
'#type' => 'textfield',
'#title' => $this
->t('Suffix'),
'#size' => '100',
'#description' => $this
->t('You can enter any html in here.'),
'#default_value' => isset($config['suffix']) ? $config['suffix'] : '',
'#prefix' => '<div class="field-suffix">',
'#suffix' => '</div>',
];
// Token support.
if (\Drupal::moduleHandler()
->moduleExists('token')) {
$form['tokens'] = [
'#title' => $this
->t('Tokens'),
'#type' => 'container',
'#states' => [
'invisible' => [
'input[name="use_token"]' => [
'checked' => FALSE,
],
],
],
];
$form['tokens']['help'] = [
'#theme' => 'token_tree_link',
'#token_types' => 'all',
'#global_types' => FALSE,
'#dialog' => TRUE,
];
}
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
$config = [];
$config['lb'] = '';
$config['lb-col'] = \Drupal::config('ds.settings')
->get('ft-show-colon');
$wrappers = [
'lb' => [
'title' => $this
->t('Label'),
],
'lbw' => [
'title' => $this
->t('Label wrapper'),
],
'ow' => [
'title' => $this
->t('Outer wrapper'),
],
'fis' => [
'title' => $this
->t('Field items'),
],
'fi' => [
'title' => $this
->t('Field item'),
],
];
foreach ($wrappers as $wrapper_key => $value) {
$config[$wrapper_key] = FALSE;
$config[$wrapper_key . '-el'] = '';
$config[$wrapper_key . '-at'] = '';
$config[$wrapper_key . '-cl'] = '';
$config[$wrapper_key . '-def-at'] = FALSE;
$config[$wrapper_key . '-def-cl'] = FALSE;
}
return $config;
}
/**
* {@inheritdoc}
*/
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;
}
$wrappers = [
'lbw' => $this
->t('Label wrapper'),
'ow' => $this
->t('Wrapper'),
'fis' => $this
->t('Field items'),
'fi' => $this
->t('Field item'),
];
foreach ($wrappers as $wrapper_key => $title) {
if (!empty($values[$wrapper_key])) {
// Enable.
$field_settings[$wrapper_key] = TRUE;
// Element.
$field_settings[$wrapper_key . '-el'] = !empty($values[$wrapper_key . '-el']) ? $values[$wrapper_key . '-el'] : 'div';
// Classes.
$field_settings[$wrapper_key . '-cl'] = !empty($values[$wrapper_key . '-cl']) ? $values[$wrapper_key . '-cl'] : '';
// Default Classes.
if (in_array($wrapper_key, [
'ow',
'lb',
])) {
$field_settings[$wrapper_key . '-def-cl'] = !empty($values[$wrapper_key . '-def-cl']) ? TRUE : FALSE;
}
// Attributes.
$field_settings[$wrapper_key . '-at'] = !empty($values[$wrapper_key . '-at']) ? $values[$wrapper_key . '-at'] : '';
// Default attributes.
$field_settings[$wrapper_key . '-def-at'] = !empty($values[$wrapper_key . '-def-at']) ? TRUE : FALSE;
// Token replacement.
/* @var \Drupal\Core\Entity\EntityInterface $entity */
if ($entity = $this
->getEntity()) {
// Tokens.
$apply_to = [
'prefix',
$wrapper_key . '-el',
$wrapper_key . '-cl',
$wrapper_key . '-at',
'suffix',
];
foreach ($apply_to as $identifier) {
if (!empty($field_settings[$identifier])) {
$field_settings[$identifier] = \Drupal::token()
->replace($field_settings[$identifier], [
$entity
->getEntityTypeId() => $entity,
], [
'clear' => TRUE,
]);
}
}
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DsFieldTemplateBase:: |
protected | property | The entity used for token replacement. | |
DsFieldTemplateBase:: |
public | function |
Get the selected configuration. Overrides DsFieldTemplateInterface:: |
|
DsFieldTemplateBase:: |
public | function |
Gets the entity this layout belongs too. Overrides DsFieldTemplateInterface:: |
|
DsFieldTemplateBase:: |
public | function |
Gets the chosen theme function. Overrides DsFieldTemplateInterface:: |
|
DsFieldTemplateBase:: |
public | function |
Set the configuration for this layout. Overrides DsFieldTemplateInterface:: |
|
DsFieldTemplateBase:: |
public | function |
Sets the entity this layout belong too. Overrides DsFieldTemplateInterface:: |
|
DsFieldTemplateBase:: |
public | function |
Constructs a Display Suite field plugin. Overrides PluginBase:: |
|
Expert:: |
public | function |
Lets you add you add additional form element for your layout. Overrides DsFieldTemplateBase:: |
|
Expert:: |
public | function |
Creates default configuration for the layout. Overrides DsFieldTemplateBase:: |
|
Expert:: |
public | function |
Massages the values before they get rendered. Overrides DsFieldTemplateBase:: |
|
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |