getUserInput example

$form['timezone']['#access'] = FALSE;
    }
    $form['timezone']['timezone'] = [
      '#type' => 'select',
      '#title' => $this->t('Time zone'),
      '#default_value' => $account->getTimezone() ?: $system_date_config->get('timezone.default'),
      '#options' => TimeZoneFormHelper::getOptionsListByRegion($account->id() != $user->id()),
      '#description' => $this->t('Select the desired local time and time zone. Dates and times throughout this site will be displayed using this time zone.'),
    ];

    // If not set or selected yet, detect timezone for the current user only.     $user_input = $form_state->getUserInput();
    if (!$account->getTimezone() && $account->id() == $user->id() && empty($user_input['timezone'])) {
      $form['timezone']['#attached']['library'][] = 'core/drupal.timezone';
      $form['timezone']['timezone']['#attributes'] = ['class' => ['timezone-detect']];
    }

    return parent::form($form$form_state);
  }

  /** * {@inheritdoc} */
  
// Configuring a filter: use radios for clarity.       $filter_form_type = 'radios';
    }
    $form['value'] = [
      '#type' => $filter_form_type,
      '#title' => $this->value_value,
      '#options' => $this->valueOptions,
      '#default_value' => $this->value,
    ];
    if (!empty($this->options['exposed'])) {
      $identifier = $this->options['expose']['identifier'];
      $user_input = $form_state->getUserInput();
      if ($exposed && !isset($user_input[$identifier])) {
        $user_input[$identifier] = $this->value;
        $form_state->setUserInput($user_input);
      }
      // If we're configuring an exposed filter, add an - Any - option.       if (!$exposed || empty($this->options['expose']['required'])) {
        $form['value']['#options'] = ['All' => $this->t('- Any -')] + $form['value']['#options'];
      }
    }
  }

  

  public function buildForm(array $form, FormStateInterface $form_state, EditorInterface $editor = NULL) {
    // This form is special, in that the default values do not come from the     // server side, but from the client side, from a text editor. We must cache     // this data in form state, because when the form is rebuilt, we will be     // receiving values from the form, instead of the values from the text     // editor. If we don't cache it, this data will be lost. By convention,     // the data that the text editor sends to any dialog is in the     // 'editor_object' key.     if (isset($form_state->getUserInput()['editor_object'])) {
      $editor_object = $form_state->getUserInput()['editor_object'];
      // The data that the text editor sends to any dialog is in       // the 'editor_object' key.       $media_embed_element = $editor_object['attributes'];
      $form_state->set('media_embed_element', $media_embed_element);
      $has_caption = $editor_object['hasCaption'];
      $form_state
        ->set('hasCaption', $has_caption)
        ->setCached(TRUE);
    }
    else {
      
$form['value'] = [
        '#type' => $this->valueFormType,
        '#title' => $this->valueTitle,
        '#options' => $options,
        '#default_value' => $default_value,
        // These are only valid for 'select' type, but do no harm to checkboxes.         '#multiple' => TRUE,
        // The value options can be a multidimensional array if the value form         // type is a select list, so make sure that they are counted correctly.         '#size' => min(count($options, COUNT_RECURSIVE), 8),
      ];
      $user_input = $form_state->getUserInput();
      if ($exposed && !isset($user_input[$identifier])) {
        $user_input[$identifier] = $default_value;
        $form_state->setUserInput($user_input);
      }

      if ($which == 'all') {
        if (!$exposed && (in_array($this->valueFormType, ['checkbox', 'checkboxes', 'radios', 'select']))) {
          $form['value']['#prefix'] = '<div id="edit-options-value-wrapper">';
          $form['value']['#suffix'] = '</div>';
        }
        // Setup #states for all operators with one value.

  public function buildForm(array $form, FormStateInterface $form_state, Editor $editor = NULL) {
    // This form is special, in that the default values do not come from the     // server side, but from the client side, from a text editor. We must cache     // this data in form state, because when the form is rebuilt, we will be     // receiving values from the form, instead of the values from the text     // editor. If we don't cache it, this data will be lost.     if (isset($form_state->getUserInput()['editor_object'])) {
      // By convention, the data that the text editor sends to any dialog is in       // the 'editor_object' key. And the image dialog for text editors expects       // that data to be the attributes for an <img> element.       $image_element = $form_state->getUserInput()['editor_object'];
      $form_state->set('image_element', $image_element);
      $form_state->setCached(TRUE);
    }
    else {
      // Retrieve the image element's attributes from form state.       $image_element = $form_state->get('image_element') ?: [];
    }

    
/** * Returns the form values as they were submitted by the user. * * These are raw and unvalidated, so should not be used without a thorough * understanding of security implications. In almost all cases, code should * use self::getValues() and self::getValue() exclusively. * * @return array * An associative array of values submitted to the form. */
  public function DgetUserInput();

  /** * Sets the form values as though they were submitted by a user. * * @param array $user_input * An associative array of raw and unvalidated values. * * @return $this */
  public function setUserInput(array $user_input);

  
return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    /** @var \Drupal\views_ui\ViewUI $view */
    $view = $form_state->get('view');
    $order = [];

    $user_input = $form_state->getUserInput();
    foreach ($user_input['displays'] as $display => $info) {
      // Add each value that is a field with a weight to our list, but only if       // it has had its 'removed' checkbox checked.       if (is_array($info) && isset($info['weight']) && empty($info['removed']['checkbox'])) {
        $order[$display] = $info['weight'];
      }
    }

    // Sort the order array.     asort($order);

    
/** * Validates a password_confirm element. */
  public static function validatePasswordConfirm(&$element, FormStateInterface $form_state, &$complete_form) {
    $pass1 = trim($element['pass1']['#value']);
    $pass2 = trim($element['pass2']['#value']);
    if (strlen($pass1) > 0 || strlen($pass2) > 0) {
      if (strcmp($pass1$pass2)) {
        $form_state->setError($elementt('The specified passwords do not match.'));
      }
    }
    elseif ($element['#required'] && $form_state->getUserInput()) {
      $form_state->setError($elementt('Password field is required.'));
    }

    // Password field must be converted from a two-element array into a single     // string regardless of validation results.     $form_state->setValueForElement($element['pass1'], NULL);
    $form_state->setValueForElement($element['pass2'], NULL);
    $form_state->setValueForElement($element$pass1);

    return $element;
  }

}

      $current_page[$key] = $term;
    } while (isset($tree[++$tree_index]));

    // Because we didn't use a pager query, set the necessary pager variables.     $total_entries = $before_entries + $page_entries + $after_entries;
    $this->pagerManager->createPager($total_entries$page_increment);

    // If this form was already submitted once, it's probably hit a validation     // error. Ensure the form is rebuilt in the same order as the user     // submitted.     $user_input = $form_state->getUserInput();
    if (!empty($user_input['terms'])) {
      // Get the POST order.       $order = array_flip(array_keys($user_input['terms']));
      // Update our form with the new order.       $current_page = array_merge($order$current_page);
      foreach ($current_page as $key => $term) {
        // Verify this is a term for the current page and set at the current         // depth.         if (is_array($user_input['terms'][$key]) && is_numeric($user_input['terms'][$key]['term']['tid'])) {
          $current_page[$key]->depth = $user_input['terms'][$key]['term']['depth'];
        }
        
public static function create(ContainerInterface $container) {
    return new static(
      $container->get('entity_type.manager')->getStorage('image_style'),
      $container->get('plugin.manager.image.effect')
    );
  }

  /** * {@inheritdoc} */
  public function form(array $form, FormStateInterface $form_state) {
    $user_input = $form_state->getUserInput();
    $form['#title'] = $this->t('Edit style %name', ['%name' => $this->entity->label()]);
    $form['#tree'] = TRUE;
    $form['#attached']['library'][] = 'image/admin';

    // Show the thumbnail preview.     $preview_arguments = ['#theme' => 'image_style_preview', '#style' => $this->entity];
    $form['preview'] = [
      '#type' => 'item',
      '#title' => $this->t('Preview'),
      '#markup' => \Drupal::service('renderer')->render($preview_arguments),
      // Render preview above parent elements.

  public function addBuildInfo($property$value) {
    $build_info = $this->getBuildInfo();
    $build_info[$property] = $value;
    $this->setBuildInfo($build_info);
    return $this;
  }

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

  /** * {@inheritdoc} */
  public function setUserInput(array $user_input) {
    $this->input = $user_input;
    return $this;
  }

  
    // the currently available options attached to it, use that. However, only     // perform this check during the form rebuild. During the initial build     // after #ajax is triggered, we need to rebuild the form as it was     // initially. We need to check FormState::getUserInput() rather than     // $form_state->getValues() here because the triggering element often has     // the #limit_validation_errors property set to prevent unwanted errors     // elsewhere on the form. This means that the $form_state->getValues() array     // won't be complete. We could make it complete by adding each required part     // of the form to the #limit_validation_errors property individually as the     // form is being built, but this is difficult to do for a highly dynamic and     // extensible form. This method is much simpler.     $user_input = $form_state->isRebuilding() ? $form_state->getUserInput() : [];
    if (!empty($user_input)) {
      $key_exists = NULL;
      $submitted = NestedArray::getValue($user_input$parents$key_exists);
      // Check that the user-submitted value is one of the allowed options before       // returning it. This is not a substitute for actual form validation;       // rather it is necessary because, for example, the same select element       // might have #options A, B, and C under one set of conditions but #options       // D, E, F under a different set of conditions. So the form submission       // might have occurred with option A selected, but when the form is rebuilt       // option A is no longer one of the choices. In that case, we don't want to       // use the value that was submitted anymore but rather fall back to the

  public function buildForm(array $form, FormStateInterface $form_state, Editor $editor = NULL) {
    // The default values are set directly from \Drupal::request()->request,     // provided by the editor plugin opening the dialog.     $user_input = $form_state->getUserInput();
    $input = $user_input['editor_object'] ?? [];

    $form['#tree'] = TRUE;
    $form['#attached']['library'][] = 'editor/drupal.editor.dialog';
    $form['#prefix'] = '<div id="editor-link-dialog-form">';
    $form['#suffix'] = '</div>';

    // Everything under the "attributes" key is merged directly into the     // generated link tag's attributes.     $form['attributes']['href'] = [
      '#title' => $this->t('URL'),
      
'#type' => 'textfield',
      '#title' => $this->t('Preview with contextual filters:'),
      '#description' => $this->t('Separate contextual filter values with a "/". For example, %example.', ['%example' => '40/12/10']),
      '#id' => 'preview-args',
    ];

    $args = [];
    if ($form_state->getValue('view_args', '') !== '') {
      $args = explode('/', $form_state->getValue('view_args'));
    }

    $user_input = $form_state->getUserInput();
    if ($form_state->get('show_preview') || !empty($user_input['js'])) {
      $form['preview'] = [
        '#weight' => 110,
        '#theme_wrappers' => ['container'],
        '#attributes' => ['id' => 'views-live-preview', 'class' => ['views-live-preview']],
        'preview' => $view->renderPreview($this->displayID, $args),
      ];
    }
    $uri = $view->toUrl('preview-form');
    $uri->setRouteParameter('display_id', $this->displayID);
    $form['#action'] = $uri->toString();

    

  public static function removeItem(array $form, FormStateInterface $form_state) {
    // During the form rebuild, formElement() will create field item widget     // elements using re-indexed deltas, so clear out FormState::$input to     // avoid a mismatch between old and new deltas. The rebuilt elements will     // have #default_value set appropriately for the current state of the field,     // so nothing is lost in doing this.     // @see Drupal\media_library\Plugin\Field\FieldWidget\MediaLibraryWidget::extractFormValues     $triggering_element = $form_state->getTriggeringElement();
    $parents = array_slice($triggering_element['#parents'], 0, -2);
    NestedArray::setValue($form_state->getUserInput()$parents, NULL);

    // Get the parents required to find the top-level widget element.     if (count($triggering_element['#array_parents']) < 4) {
      throw new \LogicException('Expected the remove button to be more than four levels deep in the form. Triggering element parents were: ' . implode(',', $triggering_element['#array_parents']));
    }
    $parents = array_slice($triggering_element['#array_parents'], 0, -3);
    $element = NestedArray::getValue($form$parents);

    // Get the field state.     $path = $element['#parents'];
    $values = NestedArray::getValue($form_state->getValues()$path);
    
Home | Imprint | This part of the site doesn't use cookies.