当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityInterface::validate方法代码示例

本文整理汇总了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);
 }
开发者ID:rlhawk,项目名称:encrypt,代码行数:30,代码来源:EncryptionProfileListBuilder.php

示例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);
     }
 }
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:27,代码来源:EntityResource.php

示例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.'));
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:15,代码来源:UserValidationTest.php

示例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();
     }
 }
开发者ID:anyforsoft,项目名称:csua_d8,代码行数:17,代码来源:FieldUnitTestBase.php

示例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)));
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:18,代码来源:UserValidationTest.php

示例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));
 }
开发者ID:Tawreh,项目名称:mtg,代码行数:12,代码来源:EntityProcessorBase.php


注:本文中的Drupal\Core\Entity\EntityInterface::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。