本文整理汇总了PHP中Drupal\Core\Entity\EntityForm::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityForm::validate方法的具体用法?PHP EntityForm::validate怎么用?PHP EntityForm::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityForm
的用法示例。
在下文中一共展示了EntityForm::validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
$entity = $this->entity;
// Check to prevent a duplicate title.
if ($form_state['values']['label'] != $entity->label() && shortcut_set_title_exists($form_state['values']['label'])) {
$form_state->setErrorByName('label', $this->t('The shortcut set %name already exists. Choose another name.', array('%name' => $form_state['values']['label'])));
}
}
示例2: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
$id = trim($form_state->getValue('type'));
// '0' is invalid, since elsewhere we check it using empty().
if ($id == '0') {
$form_state->setErrorByName('type', $this->t("Invalid machine-readable name. Enter a name other than %invalid.", array('%invalid' => $id)));
}
}
示例3: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
$toolbar =& $form_state->getValue(array('settings', 'toolbar'));
// Convert toolbar to array.
if (is_string($toolbar)) {
$toolbar = array_values(array_filter(array_map('trim', explode(',', $toolbar))));
}
\Drupal::service('plugin.manager.medium.plugin')->validateEditorForm($form, $form_state, $this->getEntity());
}
示例4: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
$rate = $form_state->getValue('rate');
$rate = trim($rate);
// @TODO Would be nice to better validate rate, maybe with preg_match
if (floatval($rate) < 0) {
$form_state->setErrorByName('rate', $this->t('Rate must be a positive number. No commas and only one decimal point.'));
}
// Save trimmed rate back to form if it passes validation.
$form_state->setValue('rate', $rate);
}
示例5: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
// Validate and each email recipient.
$recipients = explode(',', $form_state->getValue('recipients'));
foreach ($recipients as &$recipient) {
$recipient = trim($recipient);
if (!$this->emailValidator->isValid($recipient)) {
$form_state->setErrorByName('recipients', $this->t('%recipient is an invalid email address.', array('%recipient' => $recipient)));
}
}
$form_state->setValue('recipients', $recipients);
}
示例6: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
// Validate and each email recipient.
$recipients = explode(',', $form_state['values']['recipients']);
foreach ($recipients as &$recipient) {
$recipient = trim($recipient);
if (!valid_email_address($recipient)) {
$form_state->setErrorByName('recipients', $this->t('%recipient is an invalid email address.', array('%recipient' => $recipient)));
}
}
$form_state['values']['recipients'] = $recipients;
}
示例7: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
// Disallow adding an address format for a country that already has one.
if ($this->entity->isNew()) {
$country = $form_state->getValue('countryCode');
if ($this->storage->load($country)) {
$form_state->setErrorByName('countryCode', $this->t('The selected country already has an address format.'));
}
}
// Require the matching type field for the fields specified in the format.
$format = $form_state->getValue('format');
$requirements = ['%postalCode' => 'postalCodeType', '%dependentLocality' => 'dependentLocalityType', '%locality' => 'localityType', '%administrativeArea' => 'administrativeAreaType'];
foreach ($requirements as $token => $required_field) {
if (strpos($format, $token) !== FALSE && !$form_state->getValue($required_field)) {
$title = $form[$required_field]['#title'];
$form_state->setErrorByName($required_field, $this->t('%title is required.', ['%title' => $title]));
}
}
}
示例8: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
if (isset($form['default_value'])) {
$item = $form['#entity']->get($this->entity->getName());
$item->defaultValuesFormValidate($form['default_value'], $form, $form_state);
}
}
示例9: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
// @todo Move trimming upstream.
$format_format = trim($form_state->getValue('format'));
$format_name = trim($form_state->getValue('name'));
// Ensure that the values to be saved later are exactly the ones validated.
$form_state->setValueForElement($form['format'], $format_format);
$form_state->setValueForElement($form['name'], $format_name);
$format_exists = $this->queryFactory->get('filter_format')->condition('format', $format_format, '<>')->condition('name', $format_name)->execute();
if ($format_exists) {
$form_state->setErrorByName('name', $this->t('Text format names must be unique. A format named %name already exists.', array('%name' => $format_name)));
}
}
示例10: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
if ($this->plugin instanceof PluginFormInterface) {
$this->plugin->validateConfigurationForm($form, $form_state);
}
}
示例11: validate
/**
* Overrides EntityForm::validate().
*/
public function validate(array $form, array &$form_state)
{
$menu_link = $this->buildEntity($form, $form_state);
$normal_path = $this->pathAliasManager->getPathByAlias($menu_link->link_path);
if ($menu_link->link_path != $normal_path) {
drupal_set_message(t('The menu system stores system paths only, but will use the URL alias for display. %link_path has been stored as %normal_path', array('%link_path' => $menu_link->link_path, '%normal_path' => $normal_path)));
$menu_link->link_path = $normal_path;
$form_state['values']['link_path'] = $normal_path;
}
if (!UrlHelper::isExternal($menu_link->link_path)) {
$parsed_link = parse_url($menu_link->link_path);
if (isset($parsed_link['query'])) {
$menu_link->options['query'] = array();
parse_str($parsed_link['query'], $menu_link->options['query']);
} else {
// Use unset() rather than setting to empty string
// to avoid redundant serialized data being stored.
unset($menu_link->options['query']);
}
if (isset($parsed_link['fragment'])) {
$menu_link->options['fragment'] = $parsed_link['fragment'];
} else {
unset($menu_link->options['fragment']);
}
if (isset($parsed_link['path']) && $menu_link->link_path != $parsed_link['path']) {
$menu_link->link_path = $parsed_link['path'];
}
}
if (!trim($menu_link->link_path) || !drupal_valid_path($menu_link->link_path, TRUE)) {
$this->setFormError('link_path', $form_state, $this->t("The path '@link_path' is either invalid or you do not have access to it.", array('@link_path' => $menu_link->link_path)));
}
parent::validate($form, $form_state);
}
示例12: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
// The machine name field should already check to see if the requested
// machine name is available. Regardless of machine_name or human readable
// name, check to see if the provided pattern exists.
$pattern = trim($form_state->getValue('date_format_pattern'));
foreach ($this->dateFormatStorage->loadMultiple() as $format) {
if ($format->getPattern() == $pattern && ($this->entity->isNew() || $format->id() != $this->entity->id())) {
$form_state->setErrorByName('date_format_pattern', $this->t('This format already exists. Enter a unique format string.'));
continue;
}
}
}
示例13: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
// The Block Entity form puts all block plugin form elements in the
// settings form element, so just pass that to the block for validation.
$settings = new FormState(array('values' => $form_state['values']['settings']));
// Call the plugin validate handler.
$this->entity->getPlugin()->validateConfigurationForm($form, $settings);
// Update the original form values.
$form_state['values']['settings'] = $settings['values'];
}
示例14: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
if ($form_state->getErrors()) {
return;
}
$values =& $form_state->getValues();
// Moved advanced settings to regular settings.
foreach (array_keys($this->entity->getPlugins()) as $type) {
if (isset($values[$type . '_wrapper']['advanced'])) {
if (!isset($values[$type . '_configuration'])) {
$values[$type . '_configuration'] = [];
}
$values[$type . '_configuration'] += $values[$type . '_wrapper']['advanced'];
}
unset($values[$type . '_wrapper']);
}
foreach ($this->getConfigurablePlugins() as $type => $plugin) {
$plugin_state = $this->createSubFormState($type . '_configuration', $form_state);
$plugin->validateConfigurationForm($form[$type . '_configuration'], $plugin_state);
$form_state->setValue($type . '_configuration', $plugin_state->getValues());
$this->moveFormStateErrors($plugin_state, $form_state);
}
// Build the feed type object from the submitted values.
parent::validate($form, $form_state);
}
示例15: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
$this->doValidate($form, $form_state);
parent::validate($form, $form_state);
}