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


PHP FormStateInterface::getTriggeringElement方法代码示例

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


在下文中一共展示了FormStateInterface::getTriggeringElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updateStatus

 /**
  * Entity builder: updates the product status with the submitted value.
  *
  * @param string $entity_type
  *   The entity type.
  * @param \Drupal\commerce_product\Entity\ProductInterface $entity
  *   The product updated with the submitted values.
  * @param array $form
  *   The complete form array.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  *
  * @see \Drupal\node\NodeForm::form()
  */
 public static function updateStatus($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state)
 {
     $element = $form_state->getTriggeringElement();
     if (isset($element['#published_status'])) {
         $entity->setPublished($element['#published_status']);
     }
 }
开发者ID:mglaman,项目名称:drupalcamp-base,代码行数:21,代码来源:EnhancedContentEntityFormBase.php

示例2: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     if ($triggering_element = $form_state->getTriggeringElement()) {
         drupal_set_message(t('The clicked button is %name.', ['%name' => $triggering_element['#name']]));
     } else {
         drupal_set_message('There is no clicked button.');
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:11,代码来源:FormTestClickedButtonForm.php

示例3: submit

 /**
  * {@inheritdoc}
  */
 public function submit(array &$form, FormStateInterface $form_state)
 {
     if (($trigger = $form_state->getTriggeringElement()) && strpos($trigger['#name'], 'tab_selector_') === 0) {
         if (!empty($this->widget_ids[$trigger['#widget_id']])) {
             return $trigger['#widget_id'];
         }
     }
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:11,代码来源:Tabs.php

示例4: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getTriggeringElement()['#name'] == 'add') {
         $cached_values = $form_state->getTemporaryValue('wizard');
         list(, $route_parameters) = $this->getRelationshipOperationsRouteInfo($cached_values, $this->machine_name, $form_state->getValue('relationships'));
         $form_state->setRedirect($this->getAddRoute($cached_values), $route_parameters);
     }
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:11,代码来源:ManageContext.php

示例5: 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

示例6: ajaxSourceLanguageSelect

 /**
  * Ajax callback to fetch the options for target language select.
  *
  * @param array $form
  *   The form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The form state.
  *
  * @return mixed
  *   Target language select array.
  */
 public function ajaxSourceLanguageSelect(array $form, FormStateInterface $form_state)
 {
     if ($el = $form_state->getTriggeringElement()['#value']) {
         $selected_option = [$el => tmgmt_available_languages()[$el]];
         $options = array_diff(tmgmt_available_languages(), $selected_option);
         $form['info']['target_language']['#options'] = $options;
         return $form['info']['target_language'];
     }
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:20,代码来源:ContinuousJobForm.php

示例7: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($form_state->getTriggeringElement()['#name'] == 'select_id_submit') {
         $form_state->set('default_type', $form_state->getValue('id'));
         $form_state->setRebuild();
     } else {
         parent::submitForm($form, $form_state);
     }
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:12,代码来源:MetatagDefaultsForm.php

示例8: validate

 /**
  * {@inheritdoc}
  */
 public function validate(array &$form, FormStateInterface $form_state)
 {
     $uploaded_files = $form_state->getValue(['upload'], []);
     $trigger = $form_state->getTriggeringElement();
     // Only validate if we are uploading a file.
     if (empty($uploaded_files) && $trigger['#value'] == 'Upload') {
         $form_state->setError($form['widget']['upload'], t('At least one file should be uploaded.'));
     }
 }
开发者ID:DrupalTV,项目名称:DrupalTV,代码行数:12,代码来源:Upload.php

示例9: viewsFormSubmit

 /**
  * Submit handler for the views form.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  */
 public function viewsFormSubmit(&$form, FormStateInterface $form_state)
 {
     $triggering_element = $form_state->getTriggeringElement();
     if (!empty($triggering_element['#test_button'])) {
         $row_index = $triggering_element['#row_index'];
         $view_args = !empty($this->view->args) ? implode(', ', $this->view->args) : $this->t('no arguments');
         drupal_set_message($this->t('The test button at row @row_index for @view_id (@display) View with args: @args was submitted.', ['@display' => $this->view->current_display, '@view_id' => $this->view->id(), '@args' => $view_args, '@row_index' => $row_index]));
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:17,代码来源:FieldFormButtonTest.php

示例10: 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

示例11: removeItemSubmit

 /**
  * Submit callback for remove buttons.
  *
  * @param array $form
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  */
 public static function removeItemSubmit(array &$form, FormStateInterface $form_state)
 {
     $triggering_element = $form_state->getTriggeringElement();
     // Remove weight of entity being removed.
     $form_state->unsetValue(['selected', $triggering_element['#attributes']['data-remove-entity']]);
     // Remove entity itself.
     $selected_entities =& $form_state->get(['entity_browser', 'selected_entities']);
     unset($selected_entities[$triggering_element['#attributes']['data-row-id']]);
     static::saveNewOrder($form_state);
     $form_state->setRebuild();
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:17,代码来源:MultiStepDisplay.php

示例12: trigger

 /**
  * Button #submit callback: Triggers submission of element forms.
  *
  * @param array $form
  *   The form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The form state.
  */
 public static function trigger($form, FormStateInterface $form_state)
 {
     $triggered_element = $form_state->getTriggeringElement();
     if (!empty($triggered_element['#ief_submit_trigger_all'])) {
         // The parent form was submitted, process all IEFs and their children.
         static::doSubmit($form, $form_state);
     } else {
         // A specific element was submitted, process it and all of its children.
         $array_parents = $triggered_element['#array_parents'];
         $array_parents = array_slice($array_parents, 0, -2);
         $element = NestedArray::getValue($form, $array_parents);
         static::doSubmit($element, $form_state);
     }
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:22,代码来源:ElementSubmit.php

示例13: ajaxSample

 /**
  * Ajax callback to render a sample of the input date format.
  *
  * @param array $form
  *   Form API array structure.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   Form state information.
  *
  * @return AjaxResponse
  *   Ajax response with the rendered sample date using the given format. If
  *   the given format cannot be identified or was empty, the response will
  *   be empty as well.
  */
 public static function ajaxSample(array $form, FormStateInterface $form_state)
 {
     $response = new AjaxResponse();
     $format_value = NestedArray::getValue($form_state->getValues(), $form_state->getTriggeringElement()['#array_parents']);
     if (!empty($format_value)) {
         // Format the date with a custom date format with the given pattern.
         // The object is not instantiated in an Ajax context, so $this->t()
         // cannot be used here.
         $format = t('Displayed as %date_format', array('%date_format' => \Drupal::service('date.formatter')->format(REQUEST_TIME, 'custom', $format_value)));
         // Return a command instead of a string, since the Ajax framework
         // automatically prepends an additional empty DIV element for a string,
         // which breaks the layout.
         $response->addCommand(new ReplaceCommand('#edit-date-format-suffix', '<small id="edit-date-format-suffix">' . $format . '</small>'));
     }
     return $response;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:29,代码来源:DateFormat.php

示例14: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $triggering_element = $form_state->getTriggeringElement();
     // Return early if there are any errors or if a button we're not aware of
     // submitted the form.
     if ($form_state->hasAnyErrors() || $triggering_element['#name'] !== 'panels_ipe_submit') {
         return $form;
     }
     // Submit the parent form and save. This mimics the normal behavior of the
     // submit element in our parent form(s).
     parent::submitForm($form, $form_state);
     parent::save($form, $form_state);
     // Inform the App that we've created a new Block Content entity.
     $form['#attached']['drupalSettings']['panels_ipe']['new_block_content'] = $this->entity->uuid();
     return $form;
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:19,代码来源:PanelsIPEBlockContentForm.php

示例15: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     // If the form is rebuilding.
     if ($form_state->isRebuilding()) {
         // If an encryption method change triggered the rebuild.
         if ($form_state->getTriggeringElement()['#name'] == 'encryption_method') {
             // Update the encryption method plugin.
             $this->updateEncryptionMethod($form_state);
         }
     } elseif ($this->operation == "edit") {
         // Only when the form is first built.
         /* @var $encryption_profile \Drupal\encrypt\Entity\EncryptionProfile */
         $encryption_profile = $this->entity;
         $this->originalProfile = clone $encryption_profile;
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:rlhawk,项目名称:encrypt,代码行数:20,代码来源:EncryptionProfileForm.php


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