public function PrivateMessageThreadMemberFormatter::settingsForm in Private Message 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/PrivateMessageThreadMemberFormatter.php \Drupal\private_message\Plugin\Field\FieldFormatter\PrivateMessageThreadMemberFormatter::settingsForm()
Returns a form to configure settings for the formatter.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form elements for the formatter settings.
Overrides FormatterBase::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ PrivateMessageThreadMemberFormatter.php, line 146
Class
- PrivateMessageThreadMemberFormatter
- Defines the private message member field formatter.
Namespace
Drupal\private_message\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['display_type'] = [
'#title' => $this
->t('Display Type'),
'#type' => 'select',
'#options' => [
'label' => $this
->t('Label'),
'entity' => $this
->t('Entity'),
],
'#default_value' => $this
->getSetting('display_type'),
'#ajax' => [
'wrapper' => 'private_message_thread_member_formatter_settings_wrapper',
'callback' => [
$this,
'ajaxCallback',
],
],
];
$element['entity_display_mode'] = [
'#prefix' => '<div id="private_message_thread_member_formatter_settings_wrapper">',
'#suffix' => '</div>',
];
foreach ($this->entityManager
->getViewModes('user') as $display_mode_id => $display_mode) {
$options[$display_mode_id] = $display_mode['label'];
}
$setting_key = 'display_type';
if ($value = $form_state
->getValue([
'fields',
$this
->getFieldName(),
'settings_edit_form',
'settings',
$setting_key,
])) {
$display_type = $value;
}
else {
$display_type = $this
->getSetting('display_type');
}
if ($display_type == 'entity') {
$element['entity_display_mode']['#type'] = 'select';
$element['entity_display_mode']['#title'] = $this
->t('View mode');
$element['entity_display_mode']['#options'] = $options;
$element['entity_display_mode']['#default_value'] = $this
->getSetting('entity_display_mode');
}
else {
$element['entity_display_mode']['#markup'] = '';
}
$element['members_prefix'] = [
'#type' => 'textfield',
'#title' => $this
->t('Field prefix'),
'#default_value' => $this
->getSetting('members_prefix'),
];
return $element;
}