public function Link::settingsForm in Field Group Link 8
Same name and namespace in other branches
- 8.3 src/Plugin/field_group/FieldGroupFormatter/Link.php \Drupal\field_group_link\Plugin\field_group\FieldGroupFormatter\Link::settingsForm()
File
- src/
Plugin/ field_group/ FieldGroupFormatter/ Link.php, line 52
Class
- Link
- Plugin implementation of the 'link' formatter.
Namespace
Drupal\field_group_link\Plugin\field_group\FieldGroupFormatterCode
public function settingsForm() {
$form = parent::settingsForm();
$options = array(
'entity' => $this
->t('Full @entity_type page', array(
'@entity_type' => $this->group->entity_type,
)),
'custom_uri' => $this
->t('Custom URL'),
);
// TODO: Use static getter once it becomes available.
$fields = \Drupal::service('entity_field.manager')
->getFieldDefinitions($this->group->entity_type, $this->group->bundle);
foreach ($fields as $field) {
if (in_array($field
->getType(), $this->pluginDefinition['supported_link_field_types']) && $field
->getFieldStorageDefinition()
->isBaseField() == FALSE) {
$options[$field
->getName()] = $field
->getLabel();
}
}
$form['target'] = array(
'#title' => $this
->t('Link target'),
'#type' => 'select',
'#default_value' => $this
->getSetting('target'),
'#options' => $options,
);
if (isset($this->group->group_name)) {
$target_form_element = ':input[name="fields[' . $this->group->group_name . '][settings_edit_form][settings][target]"]';
}
else {
// If no group name available, we are on the add-group form.
$target_form_element = ':input[name="format_settings[target]"]';
}
$form['custom_uri'] = array(
'#type' => 'textfield',
'#title' => $this
->t('Custom URL'),
'#description' => $this
->t('Tokens are supported (install the Token module to see a list of available Tokens).'),
'#default_value' => $this
->getSetting('custom_uri'),
'#states' => array(
'visible' => array(
$target_form_element => array(
array(
'value' => 'custom_uri',
),
),
),
),
);
if (\Drupal::moduleHandler()
->moduleExists('token')) {
$form['tokens'] = array(
'#title' => $this
->t('Tokens'),
'#type' => 'container',
'#states' => array(
'visible' => array(
$target_form_element => array(
array(
'value' => 'custom_uri',
),
),
),
),
);
$form['tokens']['help'] = array(
'#theme' => 'token_tree_link',
'#token_types' => 'all',
'#global_types' => FALSE,
'#dialog' => TRUE,
);
}
$form['target_attribute'] = array(
'#title' => $this
->t('Target attribute'),
'#type' => 'select',
'#options' => array(
'default' => $this
->t('Default'),
'_blank' => $this
->t('Blank (new tab)'),
),
'#default_value' => $this
->getSetting('target_attribute'),
);
return $form;
}