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


PHP EntityInterface::getValue方法代码示例

本文整理汇总了PHP中Drupal\Core\Entity\EntityInterface::getValue方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface::getValue方法的具体用法?PHP EntityInterface::getValue怎么用?PHP EntityInterface::getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Entity\EntityInterface的用法示例。


在下文中一共展示了EntityInterface::getValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: patch

 /**
  * Responds to entity PATCH requests.
  *
  * @Thruway(name = "update", type="procedure")
  *
  * @param \Drupal\Core\Entity\EntityInterface $original_entity
  *   The original entity object.
  *
  * @return array
  *
  */
 public function patch(EntityInterface $original_entity)
 {
     $entity = entity_load($original_entity->getEntityTypeId(), $original_entity->id());
     if (!$entity) {
         throw new BadRequestHttpException(t('Invalid entity'));
     }
     $definition = $this->getPluginDefinition();
     if ($entity->getEntityTypeId() != $definition['entity_type']) {
         throw new BadRequestHttpException(t('Invalid entity type'));
     }
     if (!$entity->access('update')) {
         throw new AccessDeniedHttpException();
     }
     // Overwrite the received properties.
     foreach ($original_entity as $field_name => $field) {
         if (isset($entity->{$field_name})) {
             // It is not possible to set the language to NULL as it is automatically
             // re-initialized. As it must not be empty, skip it if it is.
             // @todo: Use the langcode entity key when available. See
             //   https://drupal.org/node/2143729.
             if ($field_name == 'langcode' && $field->isEmpty()) {
                 continue;
             }
             //                if ($field->isEmpty() && !$original_entity->get($field_name)->access('delete')) {
             //                    throw new AccessDeniedHttpException(
             //                        t('Access denied on deleting field @field.', array('@field' => $field_name))
             //                    );
             //                }
             $entity->set($field_name, $original_entity->getValue($field_name)[$field_name]);
             if (!$entity->get($field_name)->access('update')) {
                 throw new AccessDeniedHttpException(t('Access denied on updating field @field.', array('@field' => $field_name)));
             }
         }
     }
     // Validate the received data before saving.
     $this->validate($original_entity);
     try {
         $entity->save();
         //            $this->logger->notice(
         //                'Updated entity %type with ID %id.',
         //                array('%type' => $entity->getEntityTypeId(), '%id' => $entity->id())
         //            );
         // Update responses have an empty body.
         return $entity;
     } catch (EntityStorageException $e) {
         throw new HttpException(500, t('Internal Server Error'), $e);
     }
 }
开发者ID:voryx,项目名称:ThruwayDrupal,代码行数:59,代码来源:EntityResource.php

示例2: createLogMessage

 /**
  * Creates a log message when an exception occured during import.
  *
  * @param \Exception $e
  *   The exception that was thrown during processing.
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity object that was being processed.
  * @param arary $item
  *   The parser result for this entity.
  *
  * @return string
  *   The message to log.
  *
  * @todo This no longer works due to circular references.
  */
 protected function createLogMessage(\Exception $e, EntityInterface $entity, array $item)
 {
     include_once DRUPAL_ROOT . '/core/includes/utility.inc';
     $message = $e->getMessage();
     $message .= '<h3>Original item</h3>';
     $message .= '<pre>' . drupal_var_export($item) . '</pre>';
     $message .= '<h3>Entity</h3>';
     $message .= '<pre>' . drupal_var_export($entity->getValue()) . '</pre>';
     return $message;
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:25,代码来源:EntityProcessor.php


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