本文整理汇总了PHP中Drupal\Core\Entity\EntityInterface::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface::validate方法的具体用法?PHP EntityInterface::validate怎么用?PHP EntityInterface::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityInterface
的用法示例。
在下文中一共展示了EntityInterface::validate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
$row['label'] = $entity->label();
$row['id'] = $entity->id();
// Render encryption method row.
if ($encryption_method = $entity->getEncryptionMethod()) {
$row['encryption_method'] = $encryption_method->getLabel();
} else {
$row['encryption_method'] = $this->t('Error loading encryption method');
}
// Render encryption key row.
if ($key = $entity->getEncryptionKey()) {
$row['key'] = $key->label();
} else {
$row['key'] = $this->t('Error loading key');
}
// Render status report row.
if ($this->config->get('check_profile_status')) {
$errors = $entity->validate();
if (!empty($errors)) {
$row['status']['data'] = array('#theme' => 'item_list', '#items' => $errors, '#attributes' => array("class" => array("color-error")));
} else {
$row['status'] = $this->t('OK');
}
}
return $row + parent::buildRow($entity);
}
示例2: validate
/**
* Verifies that the whole entity does not violate any validation constraints.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity object.
*
* @throws \Symfony\Component\HttpKernel\Exception\HttpException
* If validation errors are found.
*/
protected function validate(EntityInterface $entity)
{
$violations = $entity->validate();
// Remove violations of inaccessible fields as they cannot stem from our
// changes.
$violations->filterByFieldAccess();
if (count($violations) > 0) {
$message = "Unprocessable Entity: validation failed.\n";
foreach ($violations as $violation) {
$message .= $violation->getPropertyPath() . ': ' . $violation->getMessage() . "\n";
}
// Instead of returning a generic 400 response we use the more specific
// 422 Unprocessable Entity code from RFC 4918. That way clients can
// distinguish between general syntax errors in bad serializations (code
// 400) and semantic errors in well-formed requests (code 422).
throw new HttpException(422, $message);
}
}
示例3: assertAllowedValuesViolation
/**
* Verifies that a AllowedValues violation exists for the given field.
*
* @param \Drupal\core\Entity\EntityInterface $entity
* The entity object to validate.
* @param string $field_name
* The name of the field to verify.
*/
protected function assertAllowedValuesViolation(EntityInterface $entity, $field_name)
{
$violations = $entity->validate();
$this->assertEqual(count($violations), 1, "Allowed values violation for {$field_name} found.");
$this->assertEqual($violations[0]->getPropertyPath(), "{$field_name}.0.value");
$this->assertEqual($violations[0]->getMessage(), t('The value you selected is not a valid choice.'));
}
示例4: entityValidateAndSave
/**
* Validate and save entity. Fail if violations are found.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity to save.
*
* @return void
*/
protected function entityValidateAndSave(EntityInterface $entity)
{
$violations = $entity->validate();
if ($violations->count()) {
$this->fail($violations);
} else {
$entity->save();
}
}
示例5: assertLengthViolation
/**
* Verifies that a length violation exists for the given field.
*
* @param \Drupal\core\Entity\EntityInterface $entity
* The entity object to validate.
* @param string $field_name
* The field that violates the maximum length.
* @param int $length
* Number of characters that was exceeded.
*/
protected function assertLengthViolation(EntityInterface $entity, $field_name, $length)
{
$violations = $entity->validate();
$this->assertEqual(count($violations), 1, "Violation found when {$field_name} is too long.");
$this->assertEqual($violations[0]->getPropertyPath(), "{$field_name}.0.value");
$field_label = $entity->get($field_name)->getFieldDefinition()->getLabel();
$this->assertEqual($violations[0]->getMessage(), t('%name: may not be longer than @max characters.', array('%name' => $field_label, '@max' => $length)));
}
示例6: entityValidate
/**
* {@inheritdoc}
*/
protected function entityValidate(EntityInterface $entity)
{
$violations = $entity->validate();
if (!count($violations)) {
return;
}
$args = ['@entity' => Unicode::strtolower($this->entityTypeLabel()), '%label' => $entity->label(), '%error' => $violations[0]->getMessage(), '@url' => $this->url('entity.feeds_feed_type.mapping', ['feeds_feed_type' => $this->feedType->id()])];
throw new ValidationException(SafeMarkup::format('The @entity %label failed to validate with the error: %error Please check your <a href="@url">mappings</a>.', $args));
}