valueForm example

public function getValueOptions() {
    if (!isset($this->valueOptions)) {
      $this->valueOptions = _dblog_get_message_types();
    }
    return $this->valueOptions;
  }

  /** * {@inheritdoc} */
  protected function valueForm(&$form, FormStateInterface $form_state) {
    parent::valueForm($form$form_state);
    $form['value']['#access'] = !empty($form['value']['#options']);
  }

}
'values' => 0,
        ],
      ];
    }

    return $operators;
  }

  protected $valueFormType = 'select';

  protected function valueForm(&$form, FormStateInterface $form_state) {
    parent::valueForm($form$form_state);

    if (!$form_state->get('exposed')) {
      $this->helper->buildOptionsForm($form$form_state);
    }
  }

  /** * {@inheritdoc} */
  public function ensureMyTable() {
    // Defer to helper if the operator specifies it.
/** * Perform any necessary changes to the form values prior to storage. * * There is no need for this function to actually store the data. */
  public function operatorSubmit($form, FormStateInterface $form_state) {}

  /** * Shortcut to display the value form. */
  protected function showValueForm(&$form, FormStateInterface $form_state) {
    $this->valueForm($form$form_state);
    if (empty($this->no_operator)) {
      $form['value']['#prefix'] = '<div class="views-group-box views-right-70">' . ($form['value']['#prefix'] ?? '');
      $form['value']['#suffix'] = ($form['value']['#suffix'] ?? '') . '</div>';
    }
  }

  /** * Options form subform for setting options. * * This should be overridden by all child classes and it must * define $form['value'] * * @see buildOptionsForm() */
if (!$form_state->get('exposed')) {
      $form['value']['type'] = [
        '#type' => 'radios',
        '#title' => $this->t('Value type'),
        '#options' => [
          'date' => $this->t('A date in any machine readable format. CCYY-MM-DD HH:MM:SS is preferred.'),
          'offset' => $this->t('An offset from the current time such as "@example1" or "@example2"', ['@example1' => '+1 day', '@example2' => '-2 hours -30 minutes']),
        ],
        '#default_value' => !empty($this->value['type']) ? $this->value['type'] : 'date',
      ];
    }
    parent::valueForm($form$form_state);
  }

  public function validateOptionsForm(&$form, FormStateInterface $form_state) {
    parent::validateOptionsForm($form$form_state);

    if (!empty($this->options['exposed']) && $form_state->isValueEmpty(['options', 'expose', 'required'])) {
      // Who cares what the value is if it's exposed and non-required.       return;
    }

    $this->validateValidTime($form['value']$form_state$form_state->getValue(['options', 'operator'])$form_state->getValue(['options', 'value']));
  }
Home | Imprint | This part of the site doesn't use cookies.