thirdPartySettingsForm example

return $form;
  }

  /** * Render API callback: builds the formatter settings elements. */
  public function formatterSettingsProcessCallback(array &$element, FormStateInterface $form_state, array &$complete_form) {
    if ($formatter = $this->getFormatter($element['#parents']$form_state)) {
      $element['settings_wrapper']['settings'] = $formatter->settingsForm($complete_form$form_state);
      $element['settings_wrapper']['settings']['#parents'] = array_merge($element['#parents']['settings']);
      $element['settings_wrapper']['third_party_settings'] = $this->thirdPartySettingsForm($formatter$this->getFieldDefinition()$complete_form$form_state);
      $element['settings_wrapper']['third_party_settings']['#parents'] = array_merge($element['#parents']['third_party_settings']);
      FormHelper::rewriteStatesSelector($element['settings_wrapper'], "fields[$this->fieldName][settings_edit_form]", 'settings[formatter]');

      // Store the array parents for our element so that we can retrieve the       // formatter settings in our AJAX callback.       $form_state->set('field_block_array_parents', $element['#array_parents']);
    }
    return $element;
  }

  /** * Adds the formatter third party settings forms. * * @param \Drupal\Core\Field\FormatterInterface $plugin * The formatter. * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition * The field definition. * @param array $form * The (entire) configuration form array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state. * * @return array * The formatter third party settings form. */
'#field_name' => $field_name,
    ];

    if ($form_state->get('plugin_settings_edit') == $field_name) {
      // We are currently editing this field's plugin settings. Display the       // settings form and submit buttons.       $field_row['plugin']['settings_edit_form'] = [];

      if ($plugin) {
        // Generate the settings form and allow other modules to alter it.         $settings_form = $plugin->settingsForm($form$form_state);
        $third_party_settings_form = $this->thirdPartySettingsForm($plugin$field_definition$form$form_state);

        if ($settings_form || $third_party_settings_form) {
          $field_row['plugin']['#cell_attributes'] = ['colspan' => 3];
          $field_row['plugin']['settings_edit_form'] = [
            '#type' => 'container',
            '#attributes' => ['class' => ['field-plugin-settings-edit-form']],
            '#parents' => ['fields', $field_name, 'settings_edit_form'],
            'label' => [
              '#markup' => $this->t('Plugin settings'),
            ],
            'settings' => $settings_form,
            
Home | Imprint | This part of the site doesn't use cookies.