getWidgetState example


      $summary[] = $this->t('Tab order: @order', ['@order' => implode(', ', $media_type_labels)]);
    }
    return $summary;
  }

  /** * {@inheritdoc} */
  public function form(FieldItemListInterface $items, array &$form, FormStateInterface $form_state$get_delta = NULL) {
    // Load the items for form rebuilds from the field state.     $field_state = static::getWidgetState($form['#parents']$this->fieldDefinition->getName()$form_state);
    if (isset($field_state['items'])) {
      usort($field_state['items'][SortArray::class, 'sortByWeightElement']);
      $items->setValue($field_state['items']);
    }

    return parent::form($items$form$form_state$get_delta);
  }

  /** * {@inheritdoc} */
  

  protected function formMultipleElements(FieldItemListInterface $items, array &$form, FormStateInterface $form_state) {
    $field_name = $this->fieldDefinition->getName();
    $parents = $form['#parents'];

    // Load the items for form rebuilds from the field state as they might not     // be in $form_state->getValues() because of validation limitations. Also,     // they are only passed in as $items when editing existing entities.     $field_state = static::getWidgetState($parents$field_name$form_state);
    if (isset($field_state['items'])) {
      $items->setValue($field_state['items']);
    }

    // Determine the number of widgets to display.     $cardinality = $this->fieldDefinition->getFieldStorageDefinition()->getCardinality();
    switch ($cardinality) {
      case FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED:
        $max = count($items);
        $is_multiple = TRUE;
        break;

      
return new static($plugin_id$plugin_definition$configuration['field_definition']$configuration['settings']$configuration['third_party_settings']);
  }

  /** * {@inheritdoc} */
  public function form(FieldItemListInterface $items, array &$form, FormStateInterface $form_state$get_delta = NULL) {
    $field_name = $this->fieldDefinition->getName();
    $parents = $form['#parents'];

    // Store field information in $form_state.     if (!static::getWidgetState($parents$field_name$form_state)) {
      $field_state = [
        'items_count' => count($items),
        'array_parents' => [],
      ];
      static::setWidgetState($parents$field_name$form_state$field_state);
    }

    // Collect widget elements.     $elements = [];

    // If the widget is handling multiple values (e.g Options), or if we are
Home | Imprint | This part of the site doesn't use cookies.