validateConfigurationForm example

/** * Form element validation handler; Invokes selection plugin's validation. * * @param array $form * The form where the settings form is being included in. * @param \Drupal\Core\Form\FormStateInterface $form_state * The form state of the (entire) configuration form. */
  public static function fieldSettingsFormValidate(array $form, FormStateInterface $form_state) {
    $field = $form_state->getFormObject()->getEntity();
    $handler = \Drupal::service('plugin.manager.entity_reference_selection')->getSelectionHandler($field);
    $handler->validateConfigurationForm($form$form_state);
  }

  /** * Determines whether the item holds an unsaved entity. * * This is notably used for "autocreate" widgets, and more generally to * support referencing freshly created entities (they will get saved * automatically as the hosting entity gets saved). * * @return bool * TRUE if the item holds an unsaved entity. */

  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form$form_state);
    /** @var \Drupal\workflows\WorkflowTypeInterface $workflow_type */
    $workflow = $this->entity;
    $workflow_type = $workflow->getTypePlugin();

    if ($workflow_type->hasFormClass(StateInterface::PLUGIN_FORM_KEY)) {
      $subform_state = SubformState::createForSubform($form['type_settings']$form$form_state);
      $this->pluginFormFactory
        ->createInstance($workflow_type, StateInterface::PLUGIN_FORM_KEY)
        ->validateConfigurationForm($form['type_settings']$subform_state);
    }
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    /** @var \Drupal\workflows\WorkflowInterface $workflow */
    $workflow = $this->entity;
    $workflow_type = $workflow->getTypePlugin();
    $state = $workflow_type->getState($form_state->getValue('id'));

    
$actions = parent::actions($form$form_state);
    unset($actions['delete']);
    return $actions;
  }

  /** * {@inheritdoc} */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form$form_state);
    if ($plugin = $this->getPlugin()) {
      $plugin->validateConfigurationForm($form$form_state);
    }
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form$form_state);
    if ($plugin = $this->getPlugin()) {
      $plugin->submitConfigurationForm($form$form_state);
    }
  }
'#default_value' => $site_config->get('slogan'),
      '#description' => $this->t("How this is used depends on your site's theme."),
    ];

    return $form;
  }

  /** * {@inheritdoc} */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->plugin->validateConfigurationForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $site_config = $this->configFactory->get('system.site');
    if (AccessResult::allowedIf(!$site_config->hasOverrides('name') && !$site_config->hasOverrides('slogan'))->isAllowed()) {
      $site_info = $form_state->getValue('site_information');
      $this->configFactory->getEditable('system.site')
        ->set('name', $site_info['site_name'])
        
$configuration_stored_out_of_band = empty($default_configuration);
      // If this plugin is configurable but has not yet had user interaction,       // the default configuration will still be active and may trigger       // validation errors. Do not trigger those validation errors until the       // form is actually saved, to allow the user to first configure other       // CKEditor 5 functionality.       $default_configurations[$plugin_id] = $default_configuration;

      if ($form_state->hasValue(['plugins', $plugin_id])) {
        $subform = $form['plugins'][$plugin_id];
        $subform_state = SubformState::createForSubform($subform$form$form_state);
        $plugin->validateConfigurationForm($subform$subform_state);
        $plugin->submitConfigurationForm($subform$subform_state);

        // If the configuration is stored out of band, ::submitConfigurationForm         // will already have stored it. If it is not stored out of band,         // populate $settings, to populate $submitted_editor.         if (!$configuration_stored_out_of_band) {
          $settings['plugins'][$plugin_id] = $plugin->getConfiguration();
        }
      }
      // @see \Drupal\ckeditor5\Plugin\Editor\CKEditor5::injectPluginSettingsForm()       elseif ($this->shouldHaveVisiblePluginSettingsForm($definition$eventual_editor_and_format_for_plugin_settings_visibility)) {
        

  abstract protected function submitLabel();

  /** * {@inheritdoc} */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    $subform_state = SubformState::createForSubform($form['settings']$form$form_state);
    $this->getPluginForm($this->block)->validateConfigurationForm($form['settings']$subform_state);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    // Call the plugin submit handler.     $subform_state = SubformState::createForSubform($form['settings']$form$form_state);
    $this->getPluginForm($this->block)->submitConfigurationForm($form$subform_state);

    // If this block is context-aware, set the context mapping.
'#default_value' => $this->configuration['upscale'],
      '#title' => $this->t('Allow Upscaling'),
      '#description' => $this->t('Let scale make images larger than their original size.'),
    ];
    return $form;
  }

  /** * {@inheritdoc} */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    parent::validateConfigurationForm($form$form_state);
    if ($form_state->isValueEmpty('width') && $form_state->isValueEmpty('height')) {
      $form_state->setErrorByName('data', $this->t('Width and height can not both be blank.'));
    }
  }

  /** * {@inheritdoc} */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    parent::submitConfigurationForm($form$form_state);

    
/** * {@inheritdoc} */
  public function build() {
    return ['#markup' => '<span>If I had more time this would be very witty :(.</span>'];
  }

  /** * {@inheritdoc} */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    parent::validateConfigurationForm($form$form_state);
    $form_state->setError($form['label'], 'Sorry system error. Please save again.');
  }

}
'#weight' => -1,
      ];
    }

    return $form;
  }

  /** * {@inheritdoc} */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    parent::validateConfigurationForm($form$form_state);

    // If no checkboxes were checked for 'target_bundles', store NULL ("all     // bundles are referenceable") rather than empty array ("no bundle is     // referenceable" - typically happens when all referenceable bundles have     // been deleted).     if ($form_state->getValue(['settings', 'handler_settings', 'target_bundles']) === []) {
      $form_state->setValue(['settings', 'handler_settings', 'target_bundles'], NULL);
    }

    // Don't store the 'target_bundles_update' button value into the field     // config settings.
// Since the overview form is further nested than expected, update the     // #parents. See \Drupal\menu_ui\MenuForm::form().     $form_state->set('menu_overview_form_parents', ['settings', 'entity_form', 'links']);

    return $form;
  }

  /** * {@inheritdoc} */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->plugin->validateConfigurationForm($form$form_state);
    if (!$this->hasMenuOverrides()) {
      $this->getEntityForm($this->menu)->validateForm($form$form_state);
    }
  }

  /** * {@inheritdoc} */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->plugin->submitConfigurationForm($form$form_state);
    if (!$this->hasMenuOverrides()) {
      
->set('type', $this->entity);
  }

  /** * {@inheritdoc} */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form$form_state);

    if (isset($form['source_dependent']['source_configuration'])) {
      // Let the selected plugin validate its settings.       $this->entity->getSource()->validateConfigurationForm($form['source_dependent']['source_configuration']$this->getSourceSubFormState($form$form_state));
    }
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $form_state->setValue('field_map', array_filter(
      $form_state->getValue('field_map', []),
      function D$item) {
        return $item != MediaSourceInterface::METADATA_FIELD_EMPTY;
      }
$form_state->setErrorByName('from][' . $from_state_id$this->t('The transition from %from to %to already exists.', [
          '%from' => $workflow->getTypePlugin()->getState($from_state_id)->label(),
          '%to' => $workflow->getTypePlugin()->getState($values['to'])->label(),
        ]));
      }
    }

    if ($workflow_type->hasFormClass(TransitionInterface::PLUGIN_FORM_KEY)) {
      $subform_state = SubformState::createForSubform($form['type_settings']$form$form_state);
      $this->pluginFormFactory
        ->createInstance($workflow_type, TransitionInterface::PLUGIN_FORM_KEY)
        ->validateConfigurationForm($form['type_settings']$subform_state);
    }
  }

  /** * {@inheritdoc} */
  public function save(array $form, FormStateInterface $form_state) {
    /** @var \Drupal\workflows\WorkflowInterface $workflow */
    $workflow = $this->entity;
    $workflow_type = $workflow->getTypePlugin();
    $transition = $workflow_type->getTransition($form_state->getValue('id'));

    
'#type' => 'submit',
      '#value' => $this->t('Save'),
      '#button_type' => 'primary',
    ];
    return $form;
  }

  /** * {@inheritdoc} */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    $form['#plugin_form']->validateConfigurationForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $link = $form['#plugin_form']->submitConfigurationForm($form$form_state);

    $this->messenger()->addStatus($this->t('The menu link has been saved.'));
    $form_state->setRedirect(
      'entity.menu.edit_form',
      [


  /** * {@inheritdoc} */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form$form_state);

    $form_state->setValue('weight', (int) $form_state->getValue('weight'));
    // The Block Entity form puts all block plugin form elements in the     // settings form element, so just pass that to the block for validation.     $this->getPluginForm($this->entity->getPlugin())->validateConfigurationForm($form['settings'], SubformState::createForSubform($form['settings']$form$form_state));
    $this->validateVisibility($form$form_state);
  }

  /** * Helper function to independently validate the visibility UI. * * @param array $form * A nested array form elements comprising the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. */
  
// Mark this as an administrative page for JavaScript ("Back to site" link).     $form['#attached']['drupalSettings']['path']['currentPathIsAdmin'] = TRUE;
    return $form;
  }

  /** * {@inheritdoc} */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    $subform_state = SubformState::createForSubform($form['layout_settings']$form$form_state);
    $this->getPluginForm($this->layout)->validateConfigurationForm($form['layout_settings']$subform_state);
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    // Call the plugin submit handler.     $subform_state = SubformState::createForSubform($form['layout_settings']$form$form_state);
    $this->getPluginForm($this->layout)->submitConfigurationForm($form['layout_settings']$subform_state);

    // If this layout is context-aware, set the context mapping.
Home | Imprint | This part of the site doesn't use cookies.