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


PHP Form\FormStateInterface类代码示例

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


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

示例1: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     /** @var \Drupal\search_api\ServerInterface $server */
     $server = $this->getEntity();
     try {
         $server->deleteAllItems();
         drupal_set_message($this->t('All indexed data was successfully deleted from the server.'));
     } catch (SearchApiException $e) {
         drupal_set_message($this->t('Indexed data could not be cleared for some indexes. Check the logs for details.'), 'error');
     }
     $failed_reindexing = array();
     $properties = array('status' => TRUE, 'read_only' => FALSE);
     foreach ($server->getIndexes($properties) as $index) {
         try {
             $index->reindex();
         } catch (SearchApiException $e) {
             $args = array('%index' => $index->label());
             watchdog_exception('search_api', $e, '%type while clearing index %index: @message in %function (line %line of %file).', $args);
             $failed_reindexing[] = $index->label();
         }
     }
     if ($failed_reindexing) {
         $args = array('@indexes' => implode(', ', $failed_reindexing));
         drupal_set_message($this->t('Failed to mark the following indexes for reindexing: @indexes. Check the logs for details.', $args), 'warning');
     }
     $form_state->setRedirect('entity.search_api_server.canonical', array('search_api_server' => $server->id()));
 }
开发者ID:curveagency,项目名称:intranet,代码行数:30,代码来源:ServerClearConfirmForm.php

示例2: submit

 /**
  * {@inheritdoc}
  */
 public function submit(array $form, FormStateInterface $form_state)
 {
     $this->entity->delete();
     drupal_set_message($this->t('Responsive image mapping %label has been deleted.', array('%label' => $this->entity->label())));
     $this->logger('responsive_image')->notice('Responsive image mapping %label has been deleted.', array('%label' => $this->entity->label()));
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:10,代码来源:ResponsiveImageMappingDeleteForm.php

示例3: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $settings = array('types' => $form_state->getValue('types'));
     $this->currentBundle->setAssignmentSettings(self::METHOD_ID, $settings)->save();
     $this->setRedirect($form_state);
     drupal_set_message($this->t('Package assignment configuration saved.'));
 }
开发者ID:atif-shaikh,项目名称:DCX-Profile,代码行数:10,代码来源:AssignmentOptionalForm.php

示例4: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->taxonomyTerm->delete();
     drupal_set_message($this->t('The forum %label and all sub-forums have been deleted.', array('%label' => $this->taxonomyTerm->label())));
     $this->logger('forum')->notice('forum: deleted %label and all its sub-forums.', array('%label' => $this->taxonomyTerm->label()));
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:10,代码来源:DeleteForm.php

示例5: validateExposed

 public function validateExposed(&$form, FormStateInterface $form_state)
 {
     if (empty($this->options['exposed'])) {
         return;
     }
     if (empty($this->options['expose']['identifier'])) {
         return;
     }
     $identifier = $this->options['expose']['identifier'];
     $input = $form_state->getValue($identifier);
     if ($this->options['is_grouped'] && isset($this->options['group_info']['group_items'][$input])) {
         $this->operator = $this->options['group_info']['group_items'][$input]['operator'];
         $input = $this->options['group_info']['group_items'][$input]['value'];
     }
     $uids = [];
     $values = $form_state->getValue($identifier);
     if ($values && (!$this->options['is_grouped'] || $this->options['is_grouped'] && $input != 'All')) {
         foreach ($values as $value) {
             $uids[] = $value['target_id'];
         }
     }
     if ($uids) {
         $this->validated_exposed_input = $uids;
     }
 }
开发者ID:318io,项目名称:318-io,代码行数:25,代码来源:Name.php

示例6: validateElement

 /**
  * Form validation handler for widget elements.
  *
  * @param array $element
  *   The form element.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The form state.
  */
 public static function validateElement(array $element, FormStateInterface $form_state)
 {
     if ($element['#required'] && $element['#value'] == '_none') {
         $form_state->setError($element, t('@name field is required.', array('@name' => $element['#title'])));
     }
     // Massage submitted form values.
     // Drupal\Core\Field\WidgetBase::submit() expects values as
     // an array of values keyed by delta first, then by column, while our
     // widgets return the opposite.
     if (is_array($element['#value'])) {
         $values = array_values($element['#value']);
     } else {
         $values = array($element['#value']);
     }
     // Filter out the 'none' option. Use a strict comparison, because
     // 0 == 'any string'.
     $index = array_search('_none', $values, TRUE);
     if ($index !== FALSE) {
         unset($values[$index]);
     }
     // Transpose selections from field => delta to delta => field.
     $items = array();
     foreach ($values as $value) {
         $items[] = array($element['#key_column'] => $value);
     }
     $form_state->setValueForElement($element, $items);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:35,代码来源:OptionsWidgetBase.php

示例7: submit

 /**
  * {@inheritdoc}
  */
 public function submit(array &$element, array &$form, FormStateInterface $form_state)
 {
     $media_entities = [];
     $upload = $form_state->getValue('upload');
     if (isset($upload['uploaded_files']) && is_array($upload['uploaded_files'])) {
         $config = $this->getConfiguration();
         $user = $this->currentUser;
         /** @var \Drupal\media_entity\MediaBundleInterface $bundle */
         $bundle = $this->entityManager->getStorage('media_bundle')->load($this->configuration['media_entity_bundle']);
         // First save the file.
         foreach ($upload['uploaded_files'] as $uploaded_file) {
             $file = $this->dropzoneJsUploadSave->saveFile($uploaded_file['path'], $config['settings']['upload_location'], $config['settings']['extensions'], $user);
             if ($file) {
                 $file->setPermanent();
                 $file->save();
                 // Now save the media entity.
                 if ($this->moduleHandler->moduleExists('media_entity')) {
                     /** @var \Drupal\media_entity\MediaInterface $media_entity */
                     $media_entity = $this->entityManager->getStorage('media')->create(['bundle' => $bundle->id(), $bundle->getTypeConfiguration()['source_field'] => $file, 'uid' => $user->id(), 'status' => TRUE, 'type' => $bundle->getType()->getPluginId()]);
                     $event = $this->eventDispatcher->dispatch(Events::MEDIA_ENTITY_CREATE, new DropzoneMediaEntityCreateEvent($media_entity, $file, $form, $form_state, $element));
                     $media_entity = $event->getMediaEntity();
                     $media_entity->save();
                     $media_entities[] = $media_entity;
                 } else {
                     drupal_set_message(t('The media entity was not saved, because the media_entity module is not enabled.'));
                 }
             }
         }
     }
     if (!empty(array_filter($media_entities))) {
         $this->selectEntities($media_entities, $form_state);
         $this->clearFormValues($element, $form_state);
     }
 }
开发者ID:DrupalTV,项目名称:DrupalTV,代码行数:37,代码来源:MediaEntityDropzoneJsEbWidget.php

示例8: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     /** @var \Drupal\payment\Plugin\Payment\LineItem\PaymentLineItemInterface $line_item */
     $line_item = $form_state->get('payment_line_item');
     $line_item->submitConfigurationForm($form['line_item'], $form_state);
     $form_state->setRedirect('user.login');
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:10,代码来源:PaymentLineItemPaymentBasicFormElements.php

示例9: submitOptionsForm

 public function submitOptionsForm(&$form, FormStateInterface $form_state)
 {
     $exposed_form_options = $form_state->getValue('exposed_form_options');
     $form_state->setValue(array('exposed_form_options', 'text_input_required_format'), $exposed_form_options['text_input_required']['format']);
     $form_state->setValue(array('exposed_form_options', 'text_input_required'), $exposed_form_options['text_input_required']['value']);
     parent::submitOptionsForm($form, $form_state);
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:7,代码来源:InputRequired.php

示例10: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state, LanguageInterface $language = NULL)
 {
     if ($language) {
         $form_state->set('langcode', $language->getId());
     }
     return parent::buildForm($form, $form_state);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:10,代码来源:ContentTranslationDeleteForm.php

示例11: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     drupal_set_message($this->t('The static context %label has been removed.', ['%label' => $this->page->getStaticContext($this->staticContext)['label']]));
     $this->page->removeStaticContext($this->staticContext);
     $this->page->save();
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
开发者ID:neeravbm,项目名称:unify-d8,代码行数:10,代码来源:StaticContextDeleteForm.php

示例12: submit

 /**
  * {@inheritdoc}
  */
 public function submit(array $form, FormStateInterface $form_state)
 {
     $this->entity->delete();
     drupal_set_message($this->t('Custom block %label has been deleted.', array('%label' => $this->entity->label())));
     $this->logger('block_content')->notice('Custom block %label has been deleted.', array('%label' => $this->entity->label()));
     $form_state->setRedirect('block_content.list');
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:10,代码来源:BlockContentDeleteForm.php

示例13: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     /* @var $instance \Drupal\mailchimp_lists\Plugin\Field\FieldType\MailchimpListsSubscription */
     $instance = $items[0];
     $subscribe_default = $instance->getSubscribe();
     $email = NULL;
     if (!empty($instance->getEntity())) {
         $email = mailchimp_lists_load_email($instance, $instance->getEntity(), FALSE);
         if ($email) {
             $subscribe_default = mailchimp_is_subscribed($instance->getFieldDefinition()->getSetting('mc_list_id'), $email);
         }
     }
     $element += array('#title' => SafeMarkup::checkPlain($element['#title']), '#type' => 'fieldset');
     $element['subscribe'] = array('#title' => t('Subscribe'), '#type' => 'checkbox', '#default_value' => $subscribe_default ? TRUE : $this->fieldDefinition->isRequired(), '#required' => $this->fieldDefinition->isRequired(), '#disabled' => $this->fieldDefinition->isRequired());
     $form_id = $form_state->getFormObject()->getFormId();
     if ($this->fieldDefinition->getSetting('show_interest_groups') || $form_id == 'field_ui_field_edit_form') {
         $mc_list = mailchimp_get_list($instance->getFieldDefinition()->getSetting('mc_list_id'));
         $element['interest_groups'] = array('#type' => 'fieldset', '#title' => SafeMarkup::checkPlain($instance->getFieldDefinition()->getSetting('interest_groups_title')), '#weight' => 100, '#states' => array('invisible' => array(':input[name="' . $instance->getFieldDefinition()->getName() . '[0][value][subscribe]"]' => array('checked' => FALSE))));
         if ($form_id == 'field_ui_field_edit_form') {
             $element['interest_groups']['#states']['invisible'] = array(':input[name="field[settings][show_interest_groups]"]' => array('checked' => FALSE));
         }
         $groups_default = $instance->getInterestGroups();
         if ($groups_default == NULL) {
             $groups_default = array();
         }
         if ($mc_list['stats']['group_count']) {
             $element['interest_groups'] += mailchimp_interest_groups_form_elements($mc_list, $groups_default, $email);
         }
     }
     return array('value' => $element);
 }
开发者ID:rafavergara,项目名称:ddv8,代码行数:34,代码来源:MailchimpListsSelectWidget.php

示例14: finish

 /**
  * {@inheritdoc}
  */
 public function finish(array &$form, FormStateInterface $form_state)
 {
     $cached_values = $form_state->getTemporaryValue('wizard');
     drupal_set_message($this->t('Value One: @one', ['@one' => $cached_values['one']]));
     drupal_set_message($this->t('Value Two: @two', ['@two' => $cached_values['two']]));
     parent::finish($form, $form_state);
 }
开发者ID:AllieRays,项目名称:debugging-drupal-8,代码行数:10,代码来源:WizardTest.php

示例15: validateMatchedPath

 /**
  * Form element validation handler for matched_path elements.
  *
  * Note that #maxlength is validated by _form_validate() already.
  *
  * This checks that the submitted value matches an active route.
  */
 public static function validateMatchedPath(&$element, FormStateInterface $form_state, &$complete_form)
 {
     if (!empty($element['#value']) && ($element['#validate_path'] || $element['#convert_path'] != self::CONVERT_NONE)) {
         /** @var \Drupal\Core\Url $url */
         if ($url = \Drupal::service('path.validator')->getUrlIfValid($element['#value'])) {
             if ($url->isExternal()) {
                 $form_state->setError($element, t('You cannot use an external URL, please enter a relative path.'));
                 return;
             }
             if ($element['#convert_path'] == self::CONVERT_NONE) {
                 // Url is valid, no conversion required.
                 return;
             }
             // We do the value conversion here whilst the Url object is in scope
             // after validation has occurred.
             if ($element['#convert_path'] == self::CONVERT_ROUTE) {
                 $form_state->setValueForElement($element, array('route_name' => $url->getRouteName(), 'route_parameters' => $url->getRouteParameters()));
                 return;
             } elseif ($element['#convert_path'] == self::CONVERT_URL) {
                 $form_state->setValueForElement($element, $url);
                 return;
             }
         }
         $form_state->setError($element, t('This path does not exist or you do not have permission to link to %path.', array('%path' => $element['#value'])));
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:33,代码来源:PathElement.php


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