getSourceFieldName example


      ],
    ];
    return $element;
  }

  /** * {@inheritdoc} */
  protected function buildEntityFormElement(MediaInterface $media, array $form, FormStateInterface $form_state$delta) {
    $element = parent::buildEntityFormElement($media$form$form_state$delta);
    $source_field = $this->getSourceFieldName($media->bundle->entity);
    if (isset($element['fields'][$source_field])) {
      $element['fields'][$source_field]['widget'][0]['#process'][] = [static::class, 'hideExtraSourceFieldComponents'];
    }
    return $element;
  }

  /** * Processes an image or file source field element. * * @param array $element * The entity form source field element. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current form state. * @param $form * The complete form. * * @return array * The processed form element. */

  protected function createSourceFieldStorage() {
    return $this->entityTypeManager
      ->getStorage('field_storage_config')
      ->create([
        'entity_type' => 'media',
        'field_name' => $this->getSourceFieldName(),
        'type' => reset($this->pluginDefinition['allowed_field_types']),
      ]);
  }

  /** * Returns the source field storage definition. * * @return \Drupal\Core\Field\FieldStorageDefinitionInterface|null * The field storage definition or NULL if it doesn't exists. */
  protected function getSourceFieldStorage() {
    
    if (!$form_display->getComponent('name')) {
      $element['fields']['name'] = [
        '#type' => 'item',
        '#title' => $this->t('Name'),
        '#markup' => $media->getName(),
      ];
    }
    $form_display->buildForm($media$element['fields']$form_state);

    // Add source field name so that it can be identified in form alter and     // widget alter hooks.     $element['fields']['#source_field_name'] = $this->getSourceFieldName($media->bundle->entity);

    // The revision log field is currently not configurable from the form     // display, so hide it by changing the access.     // @todo Make the revision_log_message field configurable in     // https://www.drupal.org/project/drupal/issues/2696555     if (isset($element['fields']['revision_log_message'])) {
      $element['fields']['revision_log_message']['#access'] = FALSE;
    }
    return $element;
  }

  
Home | Imprint | This part of the site doesn't use cookies.