public function PbfFieldWidget::settingsForm in Permissions by field 8
Returns a form to configure settings for the widget.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the widget. 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 definition for the widget settings.
Overrides EntityReferenceAutocompleteWidget::settingsForm
File
- src/
Plugin/ Field/ FieldWidget/ PbfFieldWidget.php, line 110
Class
- PbfFieldWidget
- Plugin implementation of the 'pbf_field_widget' widget.
Namespace
Drupal\pbf\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = parent::settingsForm($form, $form_state);
$field_name = $this->fieldDefinition
->getName();
$field_definition = $this->fieldDefinition;
$options = [
0 => $this
->t('Set default grant access per node'),
1 => $this
->t('Set grant access settings generally'),
];
$element['grant_global'] = array(
'#type' => 'radios',
'#title' => $this
->t('Set default grant access settings per node or define them generally'),
'#default_value' => $this
->getSetting('grant_global'),
'#options' => $options,
'#description' => $this
->t('You can set the default grant access settings for each node. Otherwise, you can set grant settings generally for every entities. Grant access settings will be then hide to users in the form element'),
);
$element['grant_public'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Public'),
'#default_value' => $this
->getSetting('grant_public'),
'#return_value' => (int) 1,
'#empty' => 0,
'#states' => array(
'visible' => array(
'input[name="fields[' . $field_name . '][settings_edit_form][settings][grant_global]"]' => array(
'checked' => TRUE,
),
),
),
];
$element['grant_view'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Grant view'),
'#default_value' => $this
->getSetting('grant_view'),
'#return_value' => (int) 1,
'#empty' => 0,
'#states' => array(
'visible' => array(
'input[name="fields[' . $field_name . '][settings_edit_form][settings][grant_global]"]' => array(
'checked' => TRUE,
),
),
),
];
$element['grant_update'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Grant update'),
'#default_value' => $this
->getSetting('grant_update'),
'#return_value' => (int) 1,
'#empty' => 0,
'#states' => array(
'visible' => array(
'input[name="fields[' . $field_name . '][settings_edit_form][settings][grant_global]"]' => array(
'checked' => TRUE,
),
),
),
];
$element['grant_delete'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Grant delete'),
'#default_value' => $this
->getSetting('grant_delete'),
'#return_value' => (int) 1,
'#empty' => 0,
'#states' => array(
'visible' => array(
'input[name="fields[' . $field_name . '][settings_edit_form][settings][grant_global]"]' => array(
'checked' => TRUE,
),
),
),
];
$element['#attached']['library'][] = 'pbf/widget';
return $element;
}