Exemple #1
0
  /**
   * {@inheritdoc}
   */
  protected function valueForm(&$form, FormStateInterface $form_state) {
    parent::valueForm($form, $form_state);

    // If we are using the date popup widget, overwrite the settings of the form
    // according to what date_popup expects.
    if ($this->options['widget_type'] == 'date_popup' && \Drupal::moduleHandler()->moduleExists('date_popup')) {
      $form['value']['#type'] = 'date_popup';
      $form['value']['#date_format'] = 'm/d/Y';
      unset($form['value']['#description']);
    }
    elseif (!$form_state->get('exposed')) {
      $form['value']['#description'] = $this->t('A date in any format understood by <a href="@doc-link">PHP</a>. For example, "@date1" or "@date2".', array(
        '@doc-link' => 'http://php.net/manual/en/function.strtotime.php',
        '@date1' => format_date(REQUEST_TIME, 'custom', 'Y-m-d H:i:s'),
        '@date2' => 'now + 1 day',
      ));
    }
  }
  /**
   * {@inheritdoc}
   */
  protected function valueForm(&$form, FormStateInterface $form_state) {
    parent::valueForm($form, $form_state);

    if (!is_array($this->value)) {
      $this->value = $this->value ? array($this->value) : array();
    }

    // Set the correct default value in case the admin-set value is used (and a
    // value is present). The value is used if the form is either not exposed,
    // or the exposed form wasn't submitted yet. (There doesn't seem to be an
    // easier way to check for that.)
    if ($this->value && (!$form_state->getUserInput() || !empty($form_state->getUserInput()['live_preview']))) {
      $form['value']['#default_value'] = $this->idsToString($this->value);
    }
  }