当前位置: 首页>>代码示例>>PHP>>正文


PHP FormStateInterface::get方法代码示例

本文整理汇总了PHP中Drupal\Core\Form\FormStateInterface::get方法的典型用法代码示例。如果您正苦于以下问题:PHP FormStateInterface::get方法的具体用法?PHP FormStateInterface::get怎么用?PHP FormStateInterface::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Form\FormStateInterface的用法示例。


在下文中一共展示了FormStateInterface::get方法的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('');
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:30,代码来源:Callbacks.php

示例2: form

 /**
  * {@inheritdoc}
  */
 public function form(array $form, FormStateInterface $form_state)
 {
     $view = $this->entity;
     $form['#prefix'] = '<div id="views-preview-wrapper" class="views-admin clearfix">';
     $form['#suffix'] = '</div>';
     $form['#id'] = 'views-ui-preview-form';
     $form_state->disableCache();
     $form['controls']['#attributes'] = array('class' => array('clearfix'));
     $form['controls']['title'] = array('#prefix' => '<h2 class="view-preview-form__title">', '#markup' => $this->t('Preview'), '#suffix' => '</h2>');
     // Add a checkbox controlling whether or not this display auto-previews.
     $form['controls']['live_preview'] = array('#type' => 'checkbox', '#id' => 'edit-displays-live-preview', '#title' => $this->t('Auto preview'), '#default_value' => \Drupal::config('views.settings')->get('ui.always_live_preview'));
     // Add the arguments textfield
     $form['controls']['view_args'] = array('#type' => 'textfield', '#title' => $this->t('Preview with contextual filters:'), '#description' => $this->t('Separate contextual filter values with a "/". For example, %example.', array('%example' => '40/12/10')), '#id' => 'preview-args');
     $args = array();
     if (!$form_state->isValueEmpty('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'] = array('#weight' => 110, '#theme_wrappers' => array('container'), '#attributes' => array('id' => 'views-live-preview'), 'preview' => $view->renderPreview($this->displayID, $args));
     }
     $uri = $view->urlInfo('preview-form');
     $uri->setRouteParameter('display_id', $this->displayID);
     $form['#action'] = $uri->toString();
     return $form;
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:29,代码来源:ViewPreviewForm.php

示例3: switchContextMode

 /**
  * Submit callback: switch a context to data selecor or direct input mode.
  */
 public function switchContextMode(array &$form, FormStateInterface $form_state)
 {
     $element_name = $form_state->getTriggeringElement()['#name'];
     $mode = $form_state->get($element_name);
     $switched_mode = $mode == 'selector' ? 'input' : 'selector';
     $form_state->set($element_name, $switched_mode);
     $form_state->setRebuild();
 }
开发者ID:DrupalTV,项目名称:DrupalTV,代码行数:11,代码来源:ContextFormTrait.php

示例4: 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')));
     }
 }
开发者ID:alexku,项目名称:travisintegrationtest,代码行数:55,代码来源:AggregatedFields.php

示例5: valueForm

  /**
   * {@inheritdoc}
   */
  protected function valueForm(&$form, FormStateInterface $form_state) {
    // @todo Hopefully we can now be more sure of what we get in $this->value.
    while (is_array($this->value) && count($this->value) < 2) {
      $this->value = $this->value ? reset($this->value) : NULL;
    }
    $form['value'] = array(
      '#type' => 'textfield',
      '#title' => !$form_state->get('exposed') ? $this->t('Value') : '',
      '#size' => 30,
      '#default_value' => isset($this->value) ? $this->value : '',
    );

    // Hide the value box if the operator is 'empty' or 'not empty'.
    // Radios share the same selector so we have to add some dummy selector.
    if (!$form_state->get('exposed')) {
      $form['value']['#states']['visible'] = array(
        ':input[name="options[operator]"],dummy-empty' => array('!value' => 'empty'),
        ':input[name="options[operator]"],dummy-not-empty' => array('!value' => 'not empty'),
      );
    }
    elseif (!empty($this->options['expose']['use_operator'])) {
      $name = $this->options['expose']['operator_id'];
      $form['value']['#states']['visible'] = array(
        ':input[name="' . $name . '"],dummy-empty' => array('!value' => 'empty'),
        ':input[name="' . $name . '"],dummy-not-empty' => array('!value' => 'not empty'),
      );
    }
  }
开发者ID:jkyto,项目名称:agolf,代码行数:31,代码来源:SearchApiFilter.php

示例6: 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);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:11,代码来源:ViewFormBase.php

示例7: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $form_state->setCached();
     $form_state->setRebuild();
     $database_class = $form_state->get('database_class');
     if ($form_state->get('database') instanceof $database_class) {
         $form_state->set('database_connection_found', TRUE);
     }
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:12,代码来源:FormTestFormStateDatabaseForm.php

示例8: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $params['from'] = \Drupal::service('simplenews.mailer')->getFrom();
     $params['context'] = $form_state->get('context');
     $subscriber = $params['context']['simplenews_subscriber'];
     \Drupal::service('plugin.manager.mail')->mail('simplenews', $form_state->get('key'), $subscriber->getMail(), $subscriber->getLangcode(), $params, $params['from']['address']);
     drupal_set_message(t('The confirmation mail has been sent.'));
     $form_state->setRedirect('<front>');
 }
开发者ID:aritnath1990,项目名称:simplenewslatest,代码行数:12,代码来源:RequestHashForm.php

示例9: submitForm

 /**
  * {@inheritdoc]
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     /** @var \Drupal\Core\Entity\EntityInterface $entity_1 */
     $entity_1 = $form_state->get('entity_1');
     $entity_1->save();
     /** @var \Drupal\Core\Entity\EntityInterface $entity_2 */
     $entity_2 = $form_state->get('entity_2');
     $entity_2->save();
     drupal_set_message($this->t('test_entities @id_1 and @id_2 have been updated.', array('@id_1' => $entity_1->id(), '@id_2' => $entity_2->id())));
 }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:13,代码来源:NestedEntityTestForm.php

示例10: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // The page might have been serialized, resulting in a new display variant
     // collection. Refresh the display variant and block objects.
     $this->displayVariant = $this->page->getVariant($form_state->get('display_variant_id'));
     $this->block = $this->displayVariant->getBlock($form_state->get('block_id'));
     $settings = (new FormState())->setValues($form_state->getValue('settings'));
     // Call the plugin validate handler.
     $this->block->validateConfigurationForm($form, $settings);
     // Update the original form values.
     $form_state->setValue('settings', $settings->getValues());
 }
开发者ID:pulibrary,项目名称:recap,代码行数:15,代码来源:DisplayVariantConfigureBlockFormBase.php

示例11: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $view = $form_state->get('view');
     $item =& $form_state->get('handler')->options;
     $type = $form_state->get('type');
     $handler = Views::handlerManager($type)->getHandler($item);
     $executable = $view->getExecutable();
     $handler->init($executable, $executable->display_handler, $item);
     $handler->submitGroupByForm($form, $form_state);
     // Store the item back on the view
     $executable->setHandler($form_state->get('display_id'), $form_state->get('type'), $form_state->get('id'), $item);
     // Write to cache
     $view->cacheSet();
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:17,代码来源:ConfigHandlerGroup.php

示例12: getSourceLangcode

 /**
  * {@inheritdoc}
  */
 public function getSourceLangcode(FormStateInterface $form_state)
 {
     if ($source = $form_state->get(['content_translation', 'source'])) {
         return $source->getId();
     }
     return FALSE;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:10,代码来源:ContentTranslationHandler.php

示例13: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $list = $form_state->get('list');
     $webhook_actions = $form_state->getValue('webhook_actions');
     $actions = array();
     foreach ($webhook_actions as $webhook_id => $enable) {
         $actions[$webhook_id] = $enable === 1;
     }
     $result = FALSE;
     if (count($actions) > 0) {
         $webhook_url = mailchimp_webhook_url();
         $webhooks = mailchimp_webhook_get($list['id']);
         if (!empty($webhooks)) {
             foreach ($webhooks as $webhook) {
                 if ($webhook['url'] == $webhook_url) {
                     // Delete current webhook.
                     mailchimp_webhook_delete($list['id'], mailchimp_webhook_url());
                 }
             }
         }
         // Add webhook with enabled actions.
         $result = mailchimp_webhook_add($list['id'], mailchimp_webhook_url(), $actions);
     }
     if ($result) {
         drupal_set_message(t('Webhooks for list "%name" have been updated.', array('%name' => $list['name'])));
     } else {
         drupal_set_message(t('Unable to update webhooks for list "%name".', array('%name' => $list['name'])), 'warning');
     }
     $form_state->setRedirect('mailchimp_lists.overview');
 }
开发者ID:rafavergara,项目名称:ddv8,代码行数:33,代码来源:MailchimpListsWebhookSettingsForm.php

示例14: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Invoke hook_uc_order($op = 'submit') to test to make sure the order can
     // be completed... used for auto payment in uc_credit.module.
     $order = $form_state->get('uc_order');
     $error = FALSE;
     // Invoke it on a per-module basis instead of all at once.
     $module_handler = \Drupal::moduleHandler();
     foreach ($module_handler->getImplementations('uc_order') as $module) {
         $function = $module . '_uc_order';
         if (function_exists($function)) {
             // $order must be passed by reference.
             $result = $function('submit', $order, NULL);
             $msg_type = 'status';
             if ($result[0]['pass'] === FALSE) {
                 $error = TRUE;
                 $msg_type = 'error';
             }
             if (!empty($result[0]['message'])) {
                 drupal_set_message($result[0]['message'], $msg_type);
             }
             // Stop invoking the hooks if there was an error.
             if ($error) {
                 break;
             }
         }
     }
     if ($error) {
         $form_state->setRedirect('uc_cart.checkout_review');
     } else {
         unset($_SESSION['uc_checkout'][$order->id()]['do_review']);
         $_SESSION['uc_checkout'][$order->id()]['do_complete'] = TRUE;
         $form_state->setRedirect('uc_cart.checkout_complete');
     }
 }
开发者ID:pedrocones,项目名称:hydrotools,代码行数:38,代码来源:CheckoutReviewForm.php

示例15:

 /**
  * {@inheritdoc}
  */
 public function &get($property) {
   if (isset(self::$inheritedKeys[$property])) {
     return $this->mainFormState->get($property);
   }
   $value = &NestedArray::getValue($this->internalStorage, (array) $property);
   return $value;
 }
开发者ID:jkyto,项目名称:agolf,代码行数:10,代码来源:SubFormState.php


注:本文中的Drupal\Core\Form\FormStateInterface::get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。