public function SocialPrivateMessageMemberFormatter::settingsForm in Open Social 8
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
- modules/
social_features/ social_private_message/ src/ Plugin/ Field/ Fieldformatter/ SocialPrivateMessageMemberFormatter.php, line 130
Class
- SocialPrivateMessageMemberFormatter
- Class SocialPrivateMessageMemberFormatter.
Namespace
Drupal\social_private_message\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['display_type'] = [
'#title' => 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'] = '';
}
return $element;
}