public function ConditionsWidget::settingsForm in Commerce Core 8.2
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 WidgetBase::settingsForm
File
- src/
Plugin/ Field/ FieldWidget/ ConditionsWidget.php, line 94
Class
- ConditionsWidget
- Plugin implementation of the 'commerce_conditions' widget.
Namespace
Drupal\commerce\Plugin\Field\FieldWidgetCode
public function settingsForm(array $form, FormStateInterface $formState) {
$entity_types = $this->entityTypeManager
->getDefinitions();
// Remove entity types for which there are no conditions.
$condition_entity_types = array_column($this->conditionManager
->getDefinitions(), 'entity_type', 'entity_type');
$entity_types = array_filter($entity_types, function ($entity_type) use ($condition_entity_types) {
/** @var \Drupal\Core\Entity\EntityType $entity_type */
return in_array($entity_type
->id(), $condition_entity_types);
});
$entity_types = array_map(function ($entity_type) {
/** @var \Drupal\Core\Entity\EntityType $entity_type */
return $entity_type
->getLabel();
}, $entity_types);
$element = [];
$element['entity_types'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Entity types'),
'#options' => $entity_types,
'#default_value' => $this
->getSetting('entity_types'),
'#description' => $this
->t('Only conditions matching the specified entity types will be displayed.'),
'#required' => TRUE,
];
return $element;
}