當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FormStateInterface::hasAnyErrors方法代碼示例

本文整理匯總了PHP中Drupal\Core\Form\FormStateInterface::hasAnyErrors方法的典型用法代碼示例。如果您正苦於以下問題:PHP FormStateInterface::hasAnyErrors方法的具體用法?PHP FormStateInterface::hasAnyErrors怎麽用?PHP FormStateInterface::hasAnyErrors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Form\FormStateInterface的用法示例。


在下文中一共展示了FormStateInterface::hasAnyErrors方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

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

示例2: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $file_upload = $this->getRequest()->files->get('files[import_tarball]', NULL, TRUE);
     $has_upload = FALSE;
     if ($file_upload && $file_upload->isValid()) {
         // The sync directory must be empty if we are doing an upload.
         $form_state->setValue('import_tarball', $file_upload->getRealPath());
         $has_upload = TRUE;
     }
     $sync_directory = $form_state->getValue('sync_directory');
     // If we've customised the sync directory ensure its good to go.
     if ($sync_directory != config_get_config_directory(CONFIG_SYNC_DIRECTORY)) {
         // Ensure it exists and is writeable.
         if (!file_prepare_directory($sync_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS)) {
             $form_state->setErrorByName('sync_directory', t('The directory %directory could not be created or could not be made writable. To proceed with the installation, either create the directory and modify its permissions manually or ensure that the installer has the permissions to create it automatically. For more information, see the <a href="@handbook_url">online handbook</a>.', array('%directory' => $sync_directory, '@handbook_url' => 'http://drupal.org/server-permissions')));
         }
     }
     // If no tarball ensure we have files.
     if (!$form_state->hasAnyErrors() && !$has_upload) {
         $sync = new FileStorage($sync_directory);
         if (count($sync->listAll()) === 0) {
             $form_state->setErrorByName('sync_directory', t('No file upload provided and the sync directory is empty'));
         }
     }
 }
開發者ID:mkudenko,項目名稱:drupal8,代碼行數:28,代碼來源:SyncConfigureForm.php

示例3: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     // Test using form cache when re-displaying a form due to validation
     // errors.
     if ($form_state->hasAnyErrors()) {
         $form_state->setCached();
     }
 }
開發者ID:aWEBoLabs,項目名稱:taxi,代碼行數:11,代碼來源:FormTestStoragePageCacheForm.php

示例4: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Return early if there are any errors.
     if ($form_state->hasAnyErrors()) {
         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:DrupalTV,項目名稱:DrupalTV,代碼行數:17,代碼來源:PanelsIPEBlockContentForm.php

示例5: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Return early if there are any errors.
     if ($form_state->hasAnyErrors()) {
         return $form;
     }
     $panels_display = $this->panelsDisplay;
     // Submit the layout form.
     $layout_form_state = (new FormState())->setValues($form_state->getValue('settings', []));
     $this->layout->submitConfigurationForm($form, $layout_form_state);
     $layout_config = $this->layout->getConfiguration();
     // Shift our blocks to the first available region. The IPE can control
     // re-assigning blocks in a smarter way.
     $region_definitions = $this->layout->getRegionDefinitions();
     $first_region = reset(array_keys($region_definitions));
     // For each block, set the region to match the new layout.
     foreach ($panels_display->getRegionAssignments() as $region => $region_assignment) {
         /** @var \Drupal\Core\Block\BlockPluginInterface $block */
         foreach ($region_assignment as $block_id => $block) {
             $block_config = $block->getConfiguration();
             // If the new layout does not have a region with the same name, use the
             // first available region.
             if (!isset($region_definitions[$block_config['region']])) {
                 $block_config['region'] = $first_region;
                 $panels_display->updateBlock($block_id, $block_config);
             }
         }
     }
     // Have our panels display use the new layout.
     $this->panelsDisplay->setLayout($this->layout, $layout_config);
     // Update tempstore.
     $this->tempStore->set($panels_display->id(), $panels_display->getConfiguration());
     $region_data = [];
     $region_content = [];
     // Compile region content and metadata.
     $regions = $panels_display->getRegionAssignments();
     foreach ($regions as $id => $label) {
         // Wrap the region with a class/data attribute that our app can use.
         $region_name = Html::getClass("block-region-{$id}");
         $region_content[$id] = ['#prefix' => '<div class="' . $region_name . '" data-region-name="' . $id . '">', '#suffix' => '</div>'];
         // Format region metadata.
         $region_data[] = ['name' => $id, 'label' => $label];
     }
     $build = $panels_display->getLayout()->build($region_content);
     $form['build'] = $build;
     $data = ['id' => $this->layout->getPluginId(), 'label' => $layout_config['label'], 'current' => TRUE, 'html' => $this->renderer->render($build), 'regions' => $region_data];
     // Add Block metadata and HTML as a drupalSetting.
     $form['#attached']['drupalSettings']['panels_ipe']['updated_layout'] = $data;
     return $form;
 }
開發者ID:DrupalTV,項目名稱:DrupalTV,代碼行數:53,代碼來源:PanelsIPELayoutForm.php

示例6: submitPreview

 /**
  * Previews our current Block configuration.
  *
  * @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.
  *
  * @return array $form
  *   The form structure.
  */
 public function submitPreview(array &$form, FormStateInterface $form_state)
 {
     // Return early if there are any errors.
     if ($form_state->hasAnyErrors()) {
         return $form;
     }
     // Get the Block instance.
     $block_instance = $this->getBlockInstance($form_state);
     // Submit the block configuration form.
     $this->submitBlock($block_instance, $form, $form_state);
     // Gather a render array for the block.
     $build = $this->buildBlockInstance($block_instance);
     // Add the preview to the backside of the card and inform JS that we need to
     // be flipped.
     $form['flipper']['back']['preview'] = $build;
     // Add a cleafix element to the end of the preview. This prevents overlaps
     // with nested float elements.
     $build['clearfix'] = ['#markup' => '<div class="clearfix"></div>'];
     $form['#attached']['drupalSettings']['panels_ipe']['toggle_preview'] = TRUE;
     return $form;
 }
開發者ID:nB-MDSO,項目名稱:mdso-d8blog,代碼行數:32,代碼來源:PanelsIPEBlockPluginForm.php

示例7: submitSelectStep

 /**
  * Form submission handler for the entity selection step.
  *
  * On success will send the user to the next step of the form to select the
  * embed display settings. On form errors, this will rebuild the form and
  * display the error messages.
  *
  * @param array $form
  *   The form array.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The form state.
  *
  * @return \Drupal\Core\Ajax\AjaxResponse
  *   The ajax response.
  */
 public function submitSelectStep(array &$form, FormStateInterface $form_state)
 {
     $response = new AjaxResponse();
     // Display errors in form, if any.
     if ($form_state->hasAnyErrors()) {
         unset($form['#prefix'], $form['#suffix']);
         $form['status_messages'] = array('#type' => 'status_messages', '#weight' => -10);
         $response->addCommand(new HtmlCommand('#entity-embed-dialog-form', $form));
     } else {
         $form_state->set('step', !empty($this->entityBrowserSettings['display_review']) ? 'review' : 'embed');
         $form_state->setRebuild(TRUE);
         $rebuild_form = $this->formBuilder->rebuildForm('entity_embed_dialog', $form_state, $form);
         unset($rebuild_form['#prefix'], $rebuild_form['#suffix']);
         $response->addCommand(new HtmlCommand('#entity-embed-dialog-form', $rebuild_form));
         $response->addCommand(new SetDialogTitleCommand('', $rebuild_form['#title']));
     }
     return $response;
 }
開發者ID:nB-MDSO,項目名稱:mdso-d8blog,代碼行數:33,代碼來源:EntityEmbedDialog.php

示例8: widgetAjaxCallback

 /**
  * Ajax callback for entity browser form.
  *
  * Allows the entity browser form to submit the form via ajax.
  *
  * @param array $form
  *   The form array.
  * @param FormStateInterface $form_state
  *   The form state object.
  *
  * @return \Drupal\Core\Ajax\AjaxResponse
  *   Response.
  */
 public function widgetAjaxCallback(array &$form, FormStateInterface $form_state)
 {
     // If we've got any validation error, print out the form again.
     if ($form_state->hasAnyErrors()) {
         return $form;
     }
     $commands = $this->getAjaxCommands($form_state);
     $response = new AjaxResponse();
     foreach ($commands as $command) {
         $response->addCommand($command);
     }
     return $response;
 }
開發者ID:nB-MDSO,項目名稱:mdso-d8blog,代碼行數:26,代碼來源:Modal.php

示例9: submitConfigurationForm

 /**
  * {@inheritdoc}
  */
 public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     if (!$form_state->hasAnyErrors()) {
         $this->setConfiguration(array_intersect_key($form_state->getValues(), $this->defaultConfiguration()));
     }
 }
開發者ID:nB-MDSO,項目名稱:mdso-d8blog,代碼行數:9,代碼來源:EmbedTypeBase.php


注:本文中的Drupal\Core\Form\FormStateInterface::hasAnyErrors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。