createSourceFieldStorage example

/** * {@inheritdoc} */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    foreach (array_intersect_key($form_state->getValues()$this->configuration) as $config_key => $config_value) {
      $this->configuration[$config_key] = $config_value;
    }

    // If no source field is explicitly set, create it now.     if (empty($this->configuration['source_field'])) {
      $field_storage = $this->createSourceFieldStorage();
      $field_storage->save();
      $this->configuration['source_field'] = $field_storage->getName();
    }
  }

  /** * Creates the source field storage definition. * * By default, the first field type listed in the plugin definition's * allowed_field_types array will be the generated field's type. * * @return \Drupal\field\FieldStorageConfigInterface * The unsaved field storage definition. */
Home | Imprint | This part of the site doesn't use cookies.