本文整理汇总了PHP中Drupal\Core\Entity\ContentEntityForm::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentEntityForm::validate方法的具体用法?PHP ContentEntityForm::validate怎么用?PHP ContentEntityForm::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\ContentEntityForm
的用法示例。
在下文中一共展示了ContentEntityForm::validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
if (!$this->pathValidator->isValid($form_state->getValue('path'))) {
$form_state->setErrorByName('path', $this->t('The shortcut must correspond to a valid path on the site.'));
}
parent::validate($form, $form_state);
}
示例2: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
if (!shortcut_valid_link($form_state['values']['path'])) {
$form_state->setErrorByName('path', $this->t('The shortcut must correspond to a valid path on the site.'));
}
parent::validate($form, $form_state);
}
示例3: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, array &$form_state)
{
parent::validate($form, $form_state);
// Ensure numeric values.
if (isset($form_state['values']['weight']) && !is_numeric($form_state['values']['weight'])) {
$this->setFormError('weight', $form_state, $this->t('Weight value must be numeric.'));
}
}
示例4: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
// Ensure numeric values.
if ($form_state->hasValue('weight') && !is_numeric($form_state->getValue('weight'))) {
$form_state->setErrorByName('weight', $this->t('Weight value must be numeric.'));
}
}
示例5: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
$order = $this->buildEntity($form, $form_state);
if ($form_state->getValue('order_modified') != $order->modified->value) {
$form_state->setErrorByName('order_modified', t('This order has been modified by another user, changes cannot be saved.'));
}
parent::validate($form, $form_state);
}
示例6: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
/* @var \Drupal\crm_core_activity\Entity\Activity $activity */
$activity = $this->buildEntity($form, $form_state);
if ($activity->get('activity_participants')->isEmpty()) {
$message = $this->t('Participants field should include at least one participant.');
$form_state->setErrorByName('activity_participants', $message);
}
}
示例7: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
$feed = $this->buildEntity($form, $form_state);
// Check for duplicate titles.
$feed_storage = $this->entityManager->getStorage('aggregator_feed');
$result = $feed_storage->getFeedDuplicates($feed);
foreach ($result as $item) {
if (strcasecmp($item->label(), $feed->label()) == 0) {
$form_state->setErrorByName('title', $this->t('A feed named %feed already exists. Enter a unique title.', array('%feed' => $feed->label())));
}
if (strcasecmp($item->getUrl(), $feed->getUrl()) == 0) {
$form_state->setErrorByName('url', $this->t('A feed with this URL %url already exists. Enter a unique URL.', array('%url' => $feed->getUrl())));
}
}
parent::validate($form, $form_state);
}
示例8: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
$node = parent::validate($form, $form_state);
if ($node->id() && node_last_changed($node->id()) > $node->getChangedTimeAcrossTranslations()) {
$form_state->setErrorByName('changed', $this->t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.'));
}
return $node;
}
示例9: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
$this->doValidate($form, $form_state);
parent::validate($form, $form_state);
}
示例10: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
$account = $this->entity;
// Validate new or changing username.
if (isset($form_state['values']['name'])) {
if ($error = user_validate_name($form_state['values']['name'])) {
$form_state->setErrorByName('name', $error);
} else {
$name_taken = (bool) $this->entityQuery->get('user')->condition('uid', (int) $account->id(), '<>')->condition('name', $form_state['values']['name'])->range(0, 1)->count()->execute();
if ($name_taken) {
$form_state->setErrorByName('name', $this->t('The name %name is already taken.', array('%name' => $form_state['values']['name'])));
}
}
}
$mail = $form_state['values']['mail'];
if (!empty($mail)) {
$mail_taken = (bool) $this->entityQuery->get('user')->condition('uid', (int) $account->id(), '<>')->condition('mail', $mail)->range(0, 1)->count()->execute();
if ($mail_taken) {
// Format error message dependent on whether the user is logged in or not.
if (\Drupal::currentUser()->isAuthenticated()) {
$form_state->setErrorByName('mail', $this->t('The email address %email is already taken.', array('%email' => $mail)));
} else {
$form_state->setErrorByName('mail', $this->t('The email address %email is already registered. <a href="@password">Have you forgotten your password?</a>', array('%email' => $mail, '@password' => url('user/password'))));
}
}
}
// Make sure the signature isn't longer than the size of the database field.
// Signatures are disabled by default, so make sure it exists first.
if (isset($form_state['values']['signature'])) {
// Move text format for user signature into 'signature_format'.
$form_state['values']['signature_format'] = $form_state['values']['signature']['format'];
// Move text value for user signature into 'signature'.
$form_state['values']['signature'] = $form_state['values']['signature']['value'];
// @todo Make the user signature field use a widget to benefit from
// automatic typed data validation in https://drupal.org/node/2227381.
$field_definitions = $this->entityManager->getFieldDefinitions('user', $this->getEntity()->bundle());
$max_length = $field_definitions['signature']->getSetting('max_length');
if (drupal_strlen($form_state['values']['signature']) > $max_length) {
$form_state->setErrorByName('signature', $this->t('The signature is too long: it must be %max characters or less.', array('%max' => $max_length)));
}
}
}
示例11: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, array &$form_state)
{
$this->doValidate($form, $form_state);
parent::validate($form, $form_state);
}
示例12: validate
/**
* Overrides Drupal\Core\Entity\EntityForm::validate().
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
$entity = $this->entity;
if (!$entity->isNew()) {
// Verify the name in case it is being changed from being anonymous.
$accounts = $this->entityManager->getStorage('user')->loadByProperties(array('name' => $form_state->getValue('name')));
$account = reset($accounts);
$form_state->setValue('uid', $account ? $account->id() : 0);
$date = $form_state->getValue('date');
if ($date instanceof DrupalDateTime && $date->hasErrors()) {
$form_state->setErrorByName('date', $this->t('You have to specify a valid date.'));
}
if ($form_state->getValue('name') && !$form_state->getValue('is_anonymous') && !$account) {
$form_state->setErrorByName('name', $this->t('You have to specify a valid author.'));
}
} elseif ($form_state->getValue('is_anonymous')) {
// Validate anonymous comment author fields (if given). If the (original)
// author of this comment was an anonymous user, verify that no registered
// user with this name exists.
if ($form_state->getValue('name')) {
$accounts = $this->entityManager->getStorage('user')->loadByProperties(array('name' => $form_state->getValue('name')));
if (!empty($accounts)) {
$form_state->setErrorByName('name', $this->t('The name you used belongs to a registered user.'));
}
}
}
}
示例13: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
$node = $this->buildEntity($form, $form_state);
if ($node->id() && node_last_changed($node->id(), $this->getFormLangcode($form_state)) > $node->getChangedTime()) {
$form_state->setErrorByName('changed', $this->t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.'));
}
// Invoke hook_node_validate() for validation needed by modules.
// Can't use \Drupal::moduleHandler()->invokeAll(), because $form_state must
// be receivable by reference.
foreach (\Drupal::moduleHandler()->getImplementations('node_validate') as $module) {
$function = $module . '_node_validate';
$function($node, $form, $form_state);
}
parent::validate($form, $form_state);
}
示例14: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
$comment = parent::validate($form, $form_state);
// Customly trigger validation of manually added fields and add in
// violations.
$violations = $comment->created->validate();
foreach ($violations as $violation) {
$form_state->setErrorByName('date', $violation->getMessage());
}
$violations = $comment->validate();
// Filter out violations for the name path.
foreach ($violations as $violation) {
if ($violation->getPropertyPath() === 'name') {
$form_state->setErrorByName('name', $violation->getMessage());
}
}
return $comment;
}
示例15: validate
/**
* {@inheritdoc}
*/
public function validate(array $form, FormStateInterface $form_state)
{
parent::validate($form, $form_state);
$message = $this->entity;
// Check if flood control has been activated for sending emails.
if (!$this->currentUser()->hasPermission('administer contact forms') && (!$message->isPersonal() || !$this->currentUser()->hasPermission('administer users'))) {
$limit = $this->config('contact.settings')->get('flood.limit');
$interval = $this->config('contact.settings')->get('flood.interval');
if (!$this->flood->isAllowed('contact', $limit, $interval)) {
$form_state->setErrorByName('', $this->t('You cannot send more than %limit messages in @interval. Try again later.', array('%limit' => $limit, '@interval' => $this->dateFormatter->formatInterval($interval))));
}
}
}