You are here

class BricksTreeDynamicWidget in Bricks​ 2.x

Same name and namespace in other branches
  1. 8 modules/bricks_dynamic/src/Plugin/Field/FieldWidget/BricksTreeDynamicWidget.php \Drupal\bricks_dynamic\Plugin\Field\FieldWidget\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"
  }
)

Hierarchy

  • class \Drupal\bricks_dynamic\Plugin\Field\FieldWidget\BricksTreeDynamicWidget extends \Drupal\dynamic_entity_reference\Plugin\Field\FieldWidget\DynamicEntityReferenceWidget

Expanded class hierarchy of BricksTreeDynamicWidget

File

modules/bricks_dynamic/src/Plugin/Field/FieldWidget/BricksTreeDynamicWidget.php, line 21

Namespace

Drupal\bricks_dynamic\Plugin\Field\FieldWidget
View source
class BricksTreeDynamicWidget extends DynamicEntityReferenceWidget {

  /**
   * {@inheritdoc}
   */
  public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
    $element = parent::formElement($items, $delta, $element, $form, $form_state);

    // #default_value is en Entity or NULL.
    _bricks_form_element_alter($element, $items[$delta], $element['target_id']['#default_value']);
    hide($element['depth']);
    return $element;
  }

  /**
   * {@inheritdoc}
   */
  protected function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state) {
    $elements = parent::formMultipleElements($items, $form, $form_state);
    $elements['#widget'] = 'bricks_tree_dynamic';
    return $elements;
  }

}

Members