本文整理汇总了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;
}
示例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'));
}
}
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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()));
}
}