public function SwitchField::settingsForm in Display Suite 8.4
Same name and namespace in other branches
- 8.2 modules/ds_extras/src/Plugin/DsField/SwitchField.php \Drupal\ds_extras\Plugin\DsField\SwitchField::settingsForm()
- 8.3 modules/ds_extras/src/Plugin/DsField/SwitchField.php \Drupal\ds_extras\Plugin\DsField\SwitchField::settingsForm()
The form that holds the settings for this plugin.
Parameters
array $form: The form definition array for the field configuration form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The renderable form array representing the entire configuration form.
Overrides DsFieldBase::settingsForm
File
- modules/
ds_extras/ src/ Plugin/ DsField/ SwitchField.php, line 121
Class
- SwitchField
- Plugin that generates a link to switch view mode with via ajax.
Namespace
Drupal\ds_extras\Plugin\DsFieldCode
public function settingsForm($form, FormStateInterface $form_state) {
$entity_type = $this
->getEntityTypeId();
$bundle = $this
->bundle();
$view_modes = $this->entityDisplayRepository
->getViewModes($entity_type);
$form['info'] = [
'#markup' => $this
->t('Enter a label for the link for the view modes you want to switch to.<br />Leave empty to hide link. They will be localized.'),
];
$config = $this
->getConfiguration();
$config = isset($config['vms']) ? $config['vms'] : [];
foreach ($view_modes as $key => $value) {
$entity_display = $this->entityTypeManager
->getStorage('entity_view_display')
->load($entity_type . '.' . $bundle . '.' . $key);
if (!empty($entity_display)) {
if ($entity_display
->status()) {
$form['vms'][$key] = [
'#type' => 'textfield',
'#default_value' => isset($config[$key]) ? $config[$key] : '',
'#size' => 20,
'#title' => Html::escape($value['label']),
];
}
}
}
return $form;
}