本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::has方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::has方法的具体用法?PHP FormStateInterface::has怎么用?PHP FormStateInterface::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Form\FormStateInterface
的用法示例。
在下文中一共展示了FormStateInterface::has方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateName
/**
* Form element validation handler for 'name' in form_test_validate_form().
*/
public function validateName(&$element, FormStateInterface $form_state)
{
$triggered = FALSE;
if ($form_state->getValue('name') == 'element_validate') {
// Alter the form element.
$element['#value'] = '#value changed by #element_validate';
// Alter the submitted value in $form_state.
$form_state->setValueForElement($element, 'value changed by setValueForElement() in #element_validate');
$triggered = TRUE;
}
if ($form_state->getValue('name') == 'element_validate_access') {
$form_state->set('form_test_name', $form_state->getValue('name'));
// Alter the form element.
$element['#access'] = FALSE;
$triggered = TRUE;
} elseif ($form_state->has('form_test_name')) {
// To simplify this test, just take over the element's value into $form_state.
$form_state->setValueForElement($element, $form_state->get('form_test_name'));
$triggered = TRUE;
}
if ($triggered) {
// Output the element's value from $form_state.
drupal_set_message(t('@label value: @value', array('@label' => $element['#title'], '@value' => $form_state->getValue('name'))));
// Trigger a form validation error to see our changes.
$form_state->setErrorByName('');
}
}
示例2: buildFieldsForm
public function buildFieldsForm(array &$form, FormStateInterface $form_state)
{
if (!$form_state->has('fields')) {
$form_state->set('fields', $this->configuration['fields']);
}
$form_state_fields = $form_state->get('fields');
// Check if we need to add a new field, or remove one.
$triggering_element = $form_state->getTriggeringElement();
if (isset($triggering_element['#name'])) {
drupal_set_message(t('Changes in this form will not be saved until the %button button at the form bottom is clicked.', array('%button' => t('Save'))), 'warning');
$button_name = $triggering_element['#name'];
if ($button_name == 'add_aggregation_field') {
// Increment $i until the corresponding field is not set, then create
// the field with that number as suffix.
for ($i = 1; isset($form_state_fields['search_api_aggregation_' . $i]); ++$i) {
}
$form_state_fields['search_api_aggregation_' . $i] = array('label' => '', 'type' => 'union', 'fields' => array());
} else {
// Get the field ID from the button name.
$field_id = substr($button_name, 25);
unset($form_state_fields[$field_id]);
}
$form_state->set('fields', $form_state_fields);
}
// Get index type descriptions.
$type_descriptions = $this->getTypeDescriptions();
$types = $this->getTypes();
// Get the available fields for this index.
$fields = $this->index->getFields(FALSE);
$field_options = array();
$field_properties = array();
// Annotate them so we can show them cleanly in the UI.
// @todo Use option groups to group fields by datasource?
/** @var \Drupal\search_api\Item\FieldInterface[] $fields */
foreach ($fields as $field_id => $field) {
$field_options[$field_id] = $field->getPrefixedLabel();
$field_properties[$field_id] = array('#attributes' => array('title' => $field_id), '#description' => $field->getDescription());
}
ksort($field_options);
$form['fields'] = array('#type' => 'container', '#attributes' => array('id' => 'search-api-alter-add-aggregation-field-settings'), '#tree' => TRUE);
foreach ($form_state_fields as $field_id => $field) {
$new = !$field['label'];
$form['fields'][$field_id] = array('#type' => 'details', '#title' => $new ? $this->t('New field') : $field['label'], '#open' => $new);
$form['fields'][$field_id]['label'] = array('#type' => 'textfield', '#title' => $this->t('New field name'), '#default_value' => $field['label'], '#required' => TRUE);
$form['fields'][$field_id]['type'] = array('#type' => 'select', '#title' => $this->t('Aggregation type'), '#options' => $types, '#default_value' => $field['type'], '#required' => TRUE);
$form['fields'][$field_id]['type_descriptions'] = $type_descriptions;
foreach (array_keys($types) as $type) {
// @todo This shouldn't rely on undocumented form array structure.
$form['fields'][$field_id]['type_descriptions'][$type]['#states']['visible'][':input[name="processors[aggregated_field][settings][fields][' . $field_id . '][type]"]']['value'] = $type;
}
// @todo Order checked fields first in list?
$form['fields'][$field_id]['fields'] = array_merge($field_properties, array('#type' => 'checkboxes', '#title' => $this->t('Contained fields'), '#options' => $field_options, '#default_value' => array_combine($field['fields'], $field['fields']), '#attributes' => array('class' => array('search-api-checkboxes-list')), '#required' => TRUE));
$form['fields'][$field_id]['actions'] = array('#type' => 'actions', 'remove' => array('#type' => 'submit', '#value' => $this->t('Remove field'), '#submit' => array(array($this, 'submitAjaxFieldButton')), '#limit_validation_errors' => array(), '#name' => 'remove_aggregation_field_' . $field_id, '#ajax' => array('callback' => array($this, 'buildAjaxAddFieldButton'), 'wrapper' => 'search-api-alter-add-aggregation-field-settings')));
}
}
示例3: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $display_id = NULL)
{
if (isset($display_id) && $form_state->has('display_id') && $display_id !== $form_state->get('display_id')) {
throw new \InvalidArgumentException('Mismatch between $form_state->get(\'display_id\') and $display_id.');
}
$this->displayID = $form_state->has('display_id') ? $form_state->get('display_id') : $display_id;
return parent::buildForm($form, $form_state);
}
示例4: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$key = 'payment_reference_element_prototype_payment';
if ($form_state->has($key)) {
$prototype_payment = $form_state->get($key);
/** @var \Drupal\payment_reference\Plugin\Payment\Type\PaymentReference $payment_type */
$payment_type = $prototype_payment->getPaymentType();
} else {
$entity_type_id = 'user';
$bundle = 'user';
$field_name = 'foobarbaz';
/** @var \Drupal\payment\Entity\PaymentInterface $prototype_payment */
$prototype_payment = entity_create('payment', array('bundle' => 'payment_reference'));
$prototype_payment->setCurrencyCode('EUR')->setOwnerId(2)->setLineItems(Generate::createPaymentLineItems());
/** @var \Drupal\payment_reference\Plugin\Payment\Type\PaymentReference $payment_type */
$payment_type = $prototype_payment->getPaymentType();
$payment_type->setEntityTypeId($entity_type_id);
$payment_type->setBundle($bundle);
$payment_type->setFieldName($field_name);
$form_state->set($key, $prototype_payment);
}
$form['payment_reference'] = array('#plugin_selector_id' => 'payment_select_list', '#prototype_payment' => $prototype_payment, '#queue_category_id' => $payment_type->getEntityTypeId() . '.' . $payment_type->getBundle() . '.' . $payment_type->getFieldName(), '#queue_owner_id' => 2, '#required' => TRUE, '#title' => 'FooBarBaz', '#type' => 'payment_reference');
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
return $form;
}
示例5: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $allowed_selectable_plugin_ids = NULL, $plugin_id = NULL, $tree = FALSE)
{
if ($form_state->has('plugin_selector')) {
$plugin_selector = $form_state->get('plugin_selector');
} else {
$selectable_plugin_discovery = new LimitedPluginDiscoveryDecorator($this->selectablePluginType->getPluginManager());
$selectable_plugin_discovery->setDiscoveryLimit(explode(',', $allowed_selectable_plugin_ids));
$selectable_plugin_manager = new PluginManagerDecorator($this->selectablePluginType->getPluginManager(), $selectable_plugin_discovery);
$plugin_selector = $this->pluginSelectorManager->createInstance($plugin_id);
$plugin_selector->setSelectablePluginType($this->selectablePluginType);
$plugin_selector->setSelectablePluginDiscovery($selectable_plugin_manager);
$plugin_selector->setSelectablePluginFactory($selectable_plugin_manager);
$plugin_selector->setRequired();
$form_state->set('plugin_selector', $plugin_selector);
}
$form['plugin'] = $plugin_selector->buildSelectorForm([], $form_state);
// Nest the selector in a tree if that's required.
if ($tree) {
$form['tree'] = array('#tree' => TRUE);
$form['tree']['plugin'] = $form['plugin'];
unset($form['plugin']);
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
return $form;
}
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:29,代码来源:AdvancedPluginSelectorBasePluginSelectorForm.php
示例6: setPluginSelector
/**
* Stores a plugin selector in the form state.
*
* @param \Drupal\Core\Form\FormStateInterface
* @param \Drupal\plugin\Plugin\Plugin\PluginSelector\PluginSelectorInterface
*
* @return string[]
* The form state storage key that contains the plugin selector.
*
* @throws \InvalidArgumentException
*/
protected static function setPluginSelector(FormStateInterface $form_state, PluginSelectorInterface $plugin_selector)
{
do {
$key = [get_class(), mt_rand()];
} while ($form_state->has($key));
$form_state->set($key, $plugin_selector);
return $key;
}
示例7: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state)
{
if ($form_state->has('json')) {
$form_state->setResponse(new JsonResponse($form_state->getValues()));
} else {
$form_state->disableRedirect();
}
}
示例8: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $order = NULL)
{
if (!$form_state->has('uc_order')) {
$form_state->set('uc_order', $order);
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['back'] = array('#type' => 'submit', '#value' => $this->t('Back'), '#submit' => array(array($this, 'back')));
$form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Submit order'), '#button_type' => 'primary');
return $form;
}
示例9: getFormLangcode
/**
* {@inheritdoc}
*/
public function getFormLangcode(FormStateInterface $form_state)
{
if (!$form_state->has('langcode')) {
// Imply a 'view' operation to ensure users edit entities in the same
// language they are displayed. This allows to keep contextual editing
// working also for multilingual entities.
$form_state->set('langcode', $this->entityManager->getTranslationFromContext($this->entity)->language()->getId());
}
return $form_state->get('langcode');
}
示例10: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$form['text'] = array('#type' => 'textfield', '#title' => t('Text field'));
$form['test_submit'] = array('#type' => 'submit', '#value' => t('Submit'));
$db = Database::getConnection('default');
$form_state->set('database', $db);
$form_state->set('database_class', get_class($db));
if ($form_state->has('database_connection_found')) {
$form['database']['#markup'] = 'Database connection found';
}
return $form;
}
示例11: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
if ($form_state->has('payment_line_item')) {
$line_item = $form_state->get('payment_line_item');
} else {
$line_item = Payment::lineItemManager()->createInstance('payment_basic');
$form_state->set('payment_line_item', $line_item);
}
$form['line_item'] = $line_item->buildConfigurationForm([], $form_state);
$form['submit'] = array('#type' => 'submit', '#value' => t('Submit'));
return $form;
}
示例12: processEntityForm
/**
* Uses inline entity form handler to add inline form to the structure.
*
* @param array $element
* An associative array containing the properties of the element.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
* @param array $complete_form
* The complete form structure.
*
* @return array
* The processed element.
*
* @see self::preRenderAjaxForm()
*/
public static function processEntityForm($element, FormStateInterface $form_state, &$complete_form)
{
if (empty($element['#ief_id'])) {
$element['#ief_id'] = \Drupal::service('uuid')->generate();
}
if (empty($element['#entity_type']) && !empty($element['#entity']) && $element['#entity'] instanceof EntityInterface) {
$element['#entity_type'] = $element['#entity']->entityTypeId();
}
if (empty($element['#bundle']) && !empty($element['#entity']) && $element['#entity'] instanceof EntityInterface) {
$element['#bundle'] = $element['#entity']->bundle();
}
// We can't do anything useful if we don't know which entity type/ bundle
// we're supposed to operate with.
if (empty($element['#entity_type']) || empty($element['#bundle'])) {
return;
}
/** @var \Drupal\inline_entity_form\InlineFormInterface $ief_handler */
$ief_handler = \Drupal::entityManager()->getHandler($element['#entity_type'], 'inline_form');
// IEF handler is a must. If one was not assigned to this entity type we can
// not proceed.
if (empty($ief_handler)) {
return;
}
// If entity object is not there we're displaying the add form. We need to
// create a new entity to be used with it.
if (empty($element['#entity'])) {
if ($element['#op'] == 'add') {
$values = ['langcode' => $element['#language']];
$bundle_key = \Drupal::entityManager()->getDefinition($element['#entity_type'])->getKey('bundle');
if ($bundle_key) {
$values[$bundle_key] = $element['#bundle'];
}
$element['#entity'] = \Drupal::entityManager()->getStorage($element['#entity_type'])->create($values);
}
}
// Put some basic information about IEF into form state.
$state = $form_state->has(['inline_entity_form', $element['#ief_id']]) ? $form_state->get(['inline_entity_form', $element['#ief_id']]) : [];
$state += ['op' => $element['#op'], 'entity' => $element['#entity']];
$form_state->set(['inline_entity_form', $element['#ief_id']], $state);
$element = $ief_handler->entityForm($element, $form_state);
// Attach submit callbacks to main submit buttons.
if ($element['#handle_submit']) {
static::attachMainSubmit($complete_form);
}
return $element;
}
示例13: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $order = NULL)
{
if ($processed = $form_state->has('order')) {
$order = $form_state->get('order');
} else {
$form_state->set('order', $order);
}
$form['#attributes']['class'][] = 'uc-cart-checkout-form';
$form['#attached']['library'][] = 'uc_cart/uc_cart.styles';
$form['panes'] = array('#tree' => TRUE);
$filter = array('enabled' => FALSE);
// If the order isn't shippable, remove panes with shippable == TRUE.
if (!$order->isShippable() && $this->config('uc_cart.settings')->get('delivery_not_shippable')) {
$filter['shippable'] = TRUE;
}
$panes = $this->checkoutPaneManager->getPanes($filter);
// Invoke the 'prepare' op of enabled panes, but only if their 'process' ops
// have not been invoked on this request (i.e. when rebuilding after AJAX).
foreach ($panes as $id => $pane) {
if (!$form_state->get(['panes', $id, 'prepared'])) {
$pane->prepare($order, $form, $form_state);
$form_state->set(['panes', $id, 'prepared'], TRUE);
$processed = FALSE;
// Make sure we save the updated order.
}
}
// Load the line items and save the order. We do this after the 'prepare'
// callbacks of enabled panes have been invoked, because these may have
// altered the order.
if (!$processed) {
$order->line_items = $order->getLineItems();
$order->save();
}
foreach ($panes as $id => $pane) {
$form['panes'][$id] = $pane->view($order, $form, $form_state);
$form['panes'][$id] += array('#type' => 'details', '#title' => SafeMarkup::checkPlain($pane->getTitle()), '#id' => $id . '-pane', '#open' => TRUE);
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['cancel'] = array('#type' => 'submit', '#value' => $this->t('Cancel'), '#validate' => array(), '#limit_validation_errors' => array(), '#submit' => array(array($this, 'cancel')));
$form['actions']['continue'] = array('#type' => 'submit', '#value' => $this->t('Review order'), '#button_type' => 'primary');
$form_state->loadInclude('uc_store', 'inc', 'includes/uc_ajax_attach');
$form['#process'][] = 'uc_ajax_process_form';
$this->session->remove('uc_checkout_review_' . $order->id());
$this->session->remove('uc_checkout_complete_' . $order->id());
return $form;
}
示例14: buildForm
/**
* {@inheritdoc}
*
* Builds a form for a single entity field.
*/
public function buildForm(array $form, FormStateInterface $form_state, EntityInterface $entity = NULL, $field_name = NULL)
{
if (!$form_state->has('entity')) {
$this->init($form_state, $entity, $field_name);
}
// Add the field form.
$form_state->get('form_display')->buildForm($entity, $form, $form_state);
// Add a dummy changed timestamp field to attach form errors to.
if ($entity instanceof EntityChangedInterface) {
$form['changed_field'] = array('#type' => 'hidden', '#value' => $entity->getChangedTime());
}
// Add a submit button. Give it a class for easy JavaScript targeting.
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save'), '#attributes' => array('class' => array('quickedit-form-submit')));
// Simplify it for optimal in-place use.
$this->simplify($form, $form_state);
return $form;
}
示例15: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
// Start the form with two checkboxes, to test different defaults, and a
// textfield, to test more than one element type.
$form = array('checkbox_1_default_off' => array('#type' => 'checkbox', '#title' => t('This checkbox defaults to unchecked'), '#default_value' => FALSE), 'checkbox_1_default_on' => array('#type' => 'checkbox', '#title' => t('This checkbox defaults to checked'), '#default_value' => TRUE), 'text_1' => array('#type' => 'textfield', '#title' => t('This textfield has a non-empty default value.'), '#default_value' => 'DEFAULT 1'));
// Provide an 'add more' button that rebuilds the form with an additional two
// checkboxes and a textfield. The test is to make sure that the rebuild
// triggered by this button preserves the user input values for the initial
// elements and initializes the new elements with the correct default values.
if (!$form_state->has('add_more')) {
$form['add_more'] = array('#type' => 'submit', '#value' => 'Add more', '#submit' => array('::addMoreSubmitForm'));
} else {
$form += array('checkbox_2_default_off' => array('#type' => 'checkbox', '#title' => t('This checkbox defaults to unchecked'), '#default_value' => FALSE), 'checkbox_2_default_on' => array('#type' => 'checkbox', '#title' => t('This checkbox defaults to checked'), '#default_value' => TRUE), 'text_2' => array('#type' => 'textfield', '#title' => t('This textfield has a non-empty default value.'), '#default_value' => 'DEFAULT 2'));
}
// A submit button that finishes the form workflow (does not rebuild).
$form['submit'] = array('#type' => 'submit', '#value' => 'Submit');
return $form;
}