BricksTreeDynamicWidget.php in Bricks 8
File
modules/bricks_dynamic/src/Plugin/Field/FieldWidget/BricksTreeDynamicWidget.php
View source
<?php
namespace Drupal\bricks_dynamic\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\dynamic_entity_reference\Plugin\Field\FieldWidget\DynamicEntityReferenceWidget;
class BricksTreeDynamicWidget extends DynamicEntityReferenceWidget {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
_bricks_form_element_alter($element, $items[$delta], $element['target_id']['#default_value']);
hide($element['depth']);
return $element;
}
protected function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state) {
$elements = parent::formMultipleElements($items, $form, $form_state);
$elements['#widget'] = 'bricks_tree_dynamic';
return $elements;
}
}
Classes
Name |
Description |
BricksTreeDynamicWidget |
Plugin annotation
@FieldWidget(
id = "bricks_tree_dynamic",
label = @Translation("Bricks tree (Dynamic)"),
description = @Translation("A tree of autocomplete text fields."),
field_types = {
"bricks_dynamic"
}
) |