hasValue example

// We need a redirect here, otherwise we would get an access denied page,       // since the current URL would be preserved and we would try to add a       // translation for a language that already has a translation.       $form_state->setRedirectUrl($entity->toUrl('edit-form'));
    }
  }

  /** * {@inheritdoc} */
  public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state) {
    if ($form_state->hasValue('content_translation')) {
      $translation = &$form_state->getValue('content_translation');
      $translation['status'] = $entity->isPublished();
    }
    parent::entityFormEntityBuild($entity_type$entity$form$form_state);
  }

}
$node = $this->createNode('select', '', ['multiple' => '']);
        $field = new ChoiceFormField($node);

        $this->assertTrue($field->isMultiple(), '->isMultiple() returns true for selects with an empty multiple attribute');
    }

    public function testSelects()
    {
        $node = $this->createSelectNode(['foo' => false, 'bar' => false]);
        $field = new ChoiceFormField($node);

        $this->assertTrue($field->hasValue(), '->hasValue() returns true for selects');
        $this->assertEquals('foo', $field->getValue(), '->getValue() returns the first option if none are selected');
        $this->assertFalse($field->isMultiple(), '->isMultiple() returns false when no multiple attribute is defined');

        $node = $this->createSelectNode(['foo' => false, 'bar' => true]);
        $field = new ChoiceFormField($node);

        $this->assertEquals('bar', $field->getValue(), '->getValue() returns the selected option');

        $field->setValue('foo');
        $this->assertEquals('foo', $field->getValue(), '->setValue() changes the selected option');

        

  public function breakpointMappingFormAjax($form, FormStateInterface $form_state) {
    return $form['keyed_styles'];
  }

  /** * {@inheritdoc} */
  public function validateForm(array &$form, FormStateInterface $form_state) {
    parent::validateForm($form$form_state);
    // Only validate on edit.     if ($form_state->hasValue('keyed_styles')) {
      // Check if another breakpoint group is selected.       if ($form_state->getValue('breakpoint_group') != $form_state->getCompleteForm()['breakpoint_group']['#default_value']) {
        // Remove the image style mappings since the breakpoint ID has changed.         $form_state->unsetValue('keyed_styles');
        return;
      }

      // Check that at least 1 image style has been selected when using sizes.       foreach ($form_state->getValue('keyed_styles') as $breakpoint_id => $multipliers) {
        foreach ($multipliers as $multiplier => $image_style_mapping) {
          if ($image_style_mapping['image_mapping_type'] === 'sizes') {
            
$element['#title'] = t('Vertical Tabs');
      $element['#title_display'] = 'invisible';
    }

    $element['#attached']['library'][] = 'core/drupal.vertical-tabs';

    // The JavaScript stores the currently selected tab in this hidden     // field so that the active tab can be restored the next time the     // form is rendered, e.g. on preview pages or when form validation     // fails.     $name = implode('__', $element['#parents']);
    if ($form_state->hasValue($name . '__active_tab')) {
      $element['#default_tab'] = $form_state->getValue($name . '__active_tab');
    }
    $element[$name . '__active_tab'] = [
      '#type' => 'hidden',
      '#default_value' => $element['#default_tab'],
      '#attributes' => ['class' => ['vertical-tabs__active-tab']],
    ];
    // Clean up the active tab value so it's not accidentally stored in     // settings forms.     $form_state->addCleanValueKey($name . '__active_tab');

    
      // @see \Drupal\ckeditor5\Plugin\CKEditor5Plugin\Image       // @see editor_image_upload_settings_form()       $default_configuration = $plugin->defaultConfiguration();
      $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();
        }
      }

  public function submitOptionsForm(&$form, FormStateInterface $form_state) {
    // Not sure I like this being here, but it seems (?) like a logical place.     $cache_plugin = $this->getPlugin('cache');
    if ($cache_plugin) {
      $cache_plugin->cacheFlush();
    }

    $section = $form_state->get('section');
    switch ($section) {
      case 'display_id':
        if ($form_state->hasValue('display_id')) {
          $this->display['new_id'] = $form_state->getValue('display_id');
        }
        break;

      case 'display_title':
        $this->display['display_title'] = $form_state->getValue('display_title');
        $this->setOption('display_description', $form_state->getValue('display_description'));
        break;

      case 'query':
        $plugin = $this->getPlugin('query');
        

  public function unsetValue($key) {
    $this->decoratedFormState->unsetValue($key);

    return $this;
  }

  /** * {@inheritdoc} */
  public function hasValue($key) {
    return $this->decoratedFormState->hasValue($key);
  }

  /** * {@inheritdoc} */
  public function isValueEmpty($key) {
    return $this->decoratedFormState->isValueEmpty($key);
  }

  /** * {@inheritdoc} */
$stored_values = $this->languageTypes->get('configurable');
    $customized = [];
    $method_weights_type = [];

    foreach ($configurable_types as $type) {
      $customized[$type] = in_array($type$stored_values);
      $method_weights = [];
      $enabled_methods = $form_state->getValue([$type, 'enabled']);
      $enabled_methods[LanguageNegotiationSelected::METHOD_ID] = TRUE;
      $method_weights_input = $form_state->getValue([$type, 'weight']);
      if ($form_state->hasValue([$type, 'configurable'])) {
        $customized[$type] = !$form_state->isValueEmpty([$type, 'configurable']);
      }

      foreach ($method_weights_input as $method_id => $weight) {
        if ($enabled_methods[$method_id]) {
          $method_weights[$method_id] = $weight;
        }
      }

      $method_weights_type[$type] = $method_weights;
      $this->languageTypes->set('negotiation.' . $type . '.method_weights', $method_weights_input)->save();
    }
/** * {@inheritdoc} */
  public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
  }

  /** * {@inheritdoc} */
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
    $this->configuration['negate'] = $form_state->getValue('negate');
    if ($form_state->hasValue('context_mapping')) {
      $this->setContextMapping($form_state->getValue('context_mapping'));
    }
  }

  /** * {@inheritdoc} */
  public function execute() {
    return $this->executableManager->execute($this);
  }

  

  protected function entityFormTitle(EntityInterface $entity) {
    $type_name = node_get_type_label($entity);
    return t('<em>Edit @type</em> @title', ['@type' => $type_name, '@title' => $entity->label()]);
  }

  /** * {@inheritdoc} */
  public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state) {
    if ($form_state->hasValue('content_translation')) {
      $translation = &$form_state->getValue('content_translation');
      $translation['status'] = $entity->isPublished();
      $account = $entity->uid->entity;
      $translation['uid'] = $account ? $account->id() : 0;
      $translation['created'] = $this->dateFormatter->format($entity->created->value, 'custom', 'Y-m-d H:i:s O');
    }
    parent::entityFormEntityBuild($entity_type$entity$form$form_state);
  }

}
'#description' => $this->t('If neither the row nor the style plugin supports fields, this field allows to enable them, so you can for example use groupby.'),
        '#default_value' => $this->options['uses_fields'],
      ];
    }
  }

  /** * {@inheritdoc} */
  public function validateOptionsForm(&$form, FormStateInterface $form_state) {
    // Don't run validation on style plugins without the grouping setting.     if ($form_state->hasValue(['style_options', 'grouping'])) {
      // Don't save grouping if no field is specified.       $groupings = $form_state->getValue(['style_options', 'grouping']);
      foreach ($groupings as $index => $grouping) {
        if (empty($grouping['field'])) {
          $form_state->unsetValue(['style_options', 'grouping', $index]);
        }
      }
    }
  }

  /** * Alter the options of a display before they are added to the view. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * @param \Drupal\views\Plugin\views\wizard\WizardInterface $wizard * The current used wizard. * @param array $display_options * The options which will be used on the view. The style plugin should * alter this to its own needs. * @param string $display_type * The display type, either block or page. */

    public function getValues(): array
    {
        $values = [];
        foreach ($this->fields->all() as $name => $field) {
            if ($field->isDisabled()) {
                continue;
            }

            if (!$field instanceof Field\FileFormField && $field->hasValue()) {
                $values[$name] = $field->getValue();
            }
        }

        return $values;
    }

    /** * Gets the file field values. */
    public function getFiles(): array
    {
// When the `alt` attribute is set to two double quotes, transform it to the     // empty string: two double quotes signify "empty alt attribute". See above.     if (trim($form_state->getValue(['attributes', 'alt'], '')) === '""') {
      $form_state->setValue(['attributes', 'alt'], '""');
    }

    // The `alt` attribute is optional: if it isn't set, the default value     // simply will not be overridden. It's important to set it to FALSE     // instead of unsetting the value. This way we explicitly inform     // the client side about the new value.     if ($form_state->hasValue(['attributes', 'alt']) && trim($form_state->getValue(['attributes', 'alt'])) === '') {
      $form_state->setValue(['attributes', 'alt'], FALSE);
    }

    // If the selected view mode matches the default on the filter, remove the     // attribute.     if (!empty($form_state->get('filter_default_view_mode')) && $form_state->getValue(['attributes', 'data-view-mode']) === $form_state->get('filter_default_view_mode')) {
      $form_state->setValue(['attributes', 'data-view-mode'], FALSE);
    }

    if ($form_state->getErrors()) {
      unset($form['#prefix']$form['#suffix']);
      
$form_state->setErrorByName('type', $this->t('You must select something to filter by.'));
    }
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $filters = dblog_filters();
    $session_filters = $this->getRequest()->getSession()->get('dblog_overview_filter', []);
    foreach ($filters as $name => $filter) {
      if ($form_state->hasValue($name)) {
        $session_filters[$name] = $form_state->getValue($name);
      }
    }
    $this->getRequest()->getSession()->set('dblog_overview_filter', $session_filters);
  }

  /** * Resets the filter form. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. */
$form_state->set('#section', $form['#section']);
    }
    // Finally, we never want these cached -- our object cache does that for us.     $form['#no_cache'] = TRUE;
  }

  /** * Return the was_defaulted, is_defaulted and revert state of a form. */
  public function getOverrideValues($form, FormStateInterface $form_state) {
    // Make sure the dropdown exists in the first place.     if ($form_state->hasValue(['override', 'dropdown'])) {
      // #default_value is used to determine whether it was the default value or not.       // So the available options are: $display, 'default' and 'default_revert', not 'defaults'.       $was_defaulted = ($form['override']['dropdown']['#default_value'] === 'defaults');
      $dropdown = $form_state->getValue(['override', 'dropdown']);
      $is_defaulted = ($dropdown === 'default');
      $revert = ($dropdown === 'default_revert');

      if ($was_defaulted !== $is_defaulted && isset($form['#section'])) {
        // We're changing which display these values apply to.         // Update the #section so it knows what to mark changed.         $form['#section'] = str_replace('default-', $form_state->get('display_id') . '-', $form['#section']);
      }
Home | Imprint | This part of the site doesn't use cookies.