php Drupal-Core-Entity-ContentEntityBase类(方法)实例源码

下面列出了php Drupal-Core-Entity-ContentEntityBase 类(方法)源码代码实例,从而了解它的用法。

作者:eigento    项目:tommiblo   
/**
  * Gets the absolute URI of an entity.
  *
  * @param \Drupal\Core\Entity\ContentEntityBase $entity
  *   The entity for which to generate the URI.
  *
  * @return string
  *   The absolute URI.
  */
 protected function getAbsoluteUri($entity)
 {
     return $entity->url('canonical', array('absolute' => TRUE));
 }

作者:ddrozdi    项目:dmap   
/**
  * {@inheritdoc}
  */
 public static function preCreate(EntityStorageInterface $storage, array &$values)
 {
     parent::preCreate($storage, $values);
     if (empty($values['type'])) {
         $values['type'] = $storage->getEntityTypeId();
     }
 }

作者:marmouse    项目:drupa   
/**
  * {@inheritdoc}
  */
 public function preSave(EntityStorageInterface $storage)
 {
     parent::preSave($storage);
     // If no owner has been set explicitly, make the current user the owner.
     if (!$this->getOwner()) {
         $this->setOwnerId($this->getCurrentUserId());
     }
 }

作者:aWEBoLab    项目:tax   
/**
  * {@inheritdoc}
  */
 public static function baseFieldDefinitions(EntityTypeInterface $entity_type)
 {
     $fields = parent::baseFieldDefinitions($entity_type);
     $fields['name'] = BaseFieldDefinition::create('string')->setLabel(t('Name'))->setDescription(t('The name of the test entity.'))->setTranslatable(TRUE)->setSetting('max_length', 32)->setDisplayOptions('view', array('label' => 'hidden', 'type' => 'string', 'weight' => -5))->setDisplayOptions('form', array('type' => 'string_textfield', 'weight' => -5));
     $fields['created'] = BaseFieldDefinition::create('created')->setLabel(t('Authored on'))->setDescription(t('Time the entity was created'))->setTranslatable(TRUE);
     $fields['user_id'] = BaseFieldDefinition::create('entity_reference')->setLabel(t('User ID'))->setDescription(t('The ID of the associated user.'))->setSetting('target_type', 'user')->setSetting('handler', 'default')->setDefaultValue(array(0 => array('target_id' => 1)))->setTranslatable(TRUE)->setDisplayOptions('form', array('type' => 'entity_reference_autocomplete', 'weight' => -1, 'settings' => array('match_operator' => 'CONTAINS', 'size' => '60', 'placeholder' => '')));
     return $fields;
 }

作者:malcomi    项目:drupalytic   
/**
  * {@inheritdoc}
  */
 public static function preCreate(EntityStorageInterface $storage_controller, array &$values)
 {
     parent::preCreate($storage_controller, $values);
     $values += array('user_id' => \Drupal::currentUser()->id());
     if (isset($values['issue_type'])) {
         $values['issue_type'] = \Drupal::service('checkstyle.issue.nodemapper')->getCheckstyleTypeId($values['issue_type']);
     }
     return FALSE;
 }

作者:pedrocone    项目:hydrotool   
/**
  * {@inheritdoc}
  */
 public static function postLoad(EntityStorageInterface $storage, array &$orders)
 {
     parent::postLoad($storage, $orders);
     foreach ($orders as $id => $order) {
         $order->products = \Drupal::entityManager()->getStorage('uc_order_product')->loadByProperties(['order_id' => $id]);
         // Load line items... has to be last after everything has been loaded.
         $order->line_items = $order->getLineItems();
     }
 }

作者:hedd    项目:content_entity_bas   
/**
  * {@inheritdoc}
  */
 public function preSaveRevision(EntityStorageInterface $storage, \stdClass $record)
 {
     parent::preSaveRevision($storage, $record);
     if (!$this->isNewRevision() && isset($this->original) && (!isset($record->revision_log) || $record->revision_log === '')) {
         // If we are updating an existing entity without adding a new
         // revision and the user did not supply a revision log, keep the existing
         // one.
         $record->revision_log = $this->original->getRevisionLog();
     }
 }

作者:aWEBoLab    项目:tax   
/**
  * {@inheritdoc}
  */
 public function postSave(EntityStorageInterface $storage, $update = TRUE)
 {
     parent::postSave($storage, $update);
     // Only change the parents if a value is set, keep the existing values if
     // not.
     if (isset($this->parent->target_id)) {
         $storage->deleteTermHierarchy(array($this->id()));
         $storage->updateTermHierarchy($this);
     }
 }

作者:davidsoloma    项目:drupalconsole.co   
/**
  * @covers ::label
  */
 public function testLabel()
 {
     // Make a mock with one method that we use as the entity's label callback.
     // We check that it is called, and that the entity's label is the callback's
     // return value.
     $callback_label = $this->randomMachineName();
     $callback_container = $this->getMock(get_class());
     $callback_container->expects($this->once())->method(__FUNCTION__)->will($this->returnValue($callback_label));
     $this->entityType->expects($this->once())->method('getLabelCallback')->will($this->returnValue(array($callback_container, __FUNCTION__)));
     $this->assertSame($callback_label, $this->entity->label());
 }

作者:Hak    项目:drupal8_trainin   
/**
  * Tests denormalization of an entity.
  */
 public function testDenormalize()
 {
     $normalized = $this->serializer->normalize($this->entity);
     foreach (array('json', 'xml') as $type) {
         $denormalized = $this->serializer->denormalize($normalized, $this->entityClass, $type, array('entity_type' => 'entity_test_mulrev'));
         $this->assertTrue($denormalized instanceof $this->entityClass, SafeMarkup::format('Denormalized entity is an instance of @class', array('@class' => $this->entityClass)));
         $this->assertIdentical($denormalized->getEntityTypeId(), $this->entity->getEntityTypeId(), 'Expected entity type found.');
         $this->assertIdentical($denormalized->bundle(), $this->entity->bundle(), 'Expected entity bundle found.');
         $this->assertIdentical($denormalized->uuid(), $this->entity->uuid(), 'Expected entity UUID found.');
     }
 }

作者:pedrocone    项目:hydrotool   
/**
  * {@inheritdoc}
  */
 public static function postLoad(EntityStorageInterface $storage, array &$items)
 {
     foreach ($items as $item) {
         $item->product = uc_product_load_variant($item->nid->target_id, $item->data->first()->toArray());
         if ($item->product) {
             $item->title = $item->product->label();
             $item->model = $item->product->model;
             $item->cost = $item->product->cost->value;
             $item->price = $item->product->price;
             $item->weight = $item->product->weight->value;
             $item->weight_units = $item->product->weight->units;
         }
         $item->module = $item->data->module;
     }
     parent::postLoad($storage, $items);
 }

作者:marmouse    项目:drupa   
/**
  * {@inheritdoc}
  */
 public function postSave(EntityStorageInterface $storage, $update = TRUE)
 {
     parent::postSave($storage, $update);
     // If no order number has been set explicitly, set it to the order id.
     if (!$this->getOrderNumber()) {
         $this->setOrderNumber($this->id());
         $this->save();
     }
     // Ensure there's a back-reference on each line item.
     foreach ($this->getLineItems() as $line_item) {
         if ($line_item->order_id->isEmpty()) {
             $line_item->order_id = $this->id();
             $line_item->save();
         }
     }
 }

作者:ravindrasingh2    项目:Drupal-8-r   
/**
  * {@inheritdoc}
  */
 public static function postDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::postDelete($storage, $entities);
     $uids = array_keys($entities);
     \Drupal::service('user.data')->delete(NULL, $uids);
 }

作者:shume    项目:blo   
/**
  * {@inheritdoc}
  */
 public static function preDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::preDelete($storage, $entities);
     /** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
     $menu_link_manager = \Drupal::service('plugin.manager.menu.link');
     foreach ($entities as $menu_link) {
         /** @var \Drupal\menu_link_content\Entity\MenuLinkContent $menu_link */
         $menu_link_manager->removeDefinition($menu_link->getPluginId(), FALSE);
     }
 }

作者:brstd    项目:gap   
/**
  * {@inheritdoc}
  */
 public function access($operation = 'view', AccountInterface $account = NULL, $return_as_object = FALSE)
 {
     if ($operation == 'create') {
         return parent::access($operation, $account, $return_as_object);
     }
     return \Drupal::entityManager()->getAccessControlHandler($this->entityTypeId)->access($this, $operation, $this->prepareLangcode(), $account, $return_as_object);
 }

作者:papillon-cendr    项目:d   
/**
  * {@inheritdoc}
  */
 public static function postDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::postDelete($storage, $entities);
     if (\Drupal::moduleHandler()->moduleExists('block')) {
         // Make sure there are no active blocks for these feeds.
         $ids = \Drupal::entityQuery('block')->condition('plugin', 'aggregator_feed_block')->condition('settings.feed', array_keys($entities))->execute();
         if ($ids) {
             $block_storage = \Drupal::entityManager()->getStorage('block');
             $block_storage->delete($block_storage->loadMultiple($ids));
         }
     }
 }

作者:justincletu    项目:webdrupalpr   
/**
  * {@inheritdoc}
  */
 public function postSave(EntityStorageInterface $storage, $update = TRUE)
 {
     parent::postSave($storage, $update);
     // Ensure there's a back-reference on each product variation.
     foreach ($this->variations as $item) {
         $variation = $item->entity;
         if ($variation->product_id->isEmpty()) {
             $variation->product_id = $this->id();
             $variation->save();
         }
     }
 }

作者:sedurz    项目:ildeposito   
/**
  * Saves the entity.
  * Mostly, you'd better use WorkflowTransitionInterface::execute();
  *
  * {@inheritdoc}
  */
 public function save()
 {
     // return parent::save();
     // Avoid custom actions for subclass WorkflowScheduledTransition.
     if ($this->isScheduled()) {
         return parent::save();
     }
     if ($this->getEntityTypeId() != 'workflow_transition') {
         return parent::save();
     }
     $transition = $this;
     $entity_type = $transition->getTargetEntityTypeId();
     $entity_id = $transition->getTargetEntityId();
     $field_name = $transition->getFieldName();
     // Remove any scheduled state transitions.
     foreach (WorkflowScheduledTransition::loadMultipleByProperties($entity_type, [$entity_id], [], $field_name) as $scheduled_transition) {
         /* @var WorkflowTransitionInterface $scheduled_transition */
         $scheduled_transition->delete();
     }
     // Check for no transition.
     if ($this->getFromSid() == $this->getToSid()) {
         if (!$this->getComment()) {
             // Write comment into history though.
             return SAVED_UPDATED;
         }
     }
     $hid = $this->id();
     if (!$hid) {
         // Insert the transition. Make sure it hasn't already been inserted.
         // @todo: Allow a scheduled transition per revision.
         // @todo: Allow a state per language version (langcode).
         $found_transition = self::loadByProperties($entity_type, $entity_id, [], $field_name);
         if ($found_transition && $found_transition->getTimestamp() == REQUEST_TIME && $found_transition->getToSid() == $this->getToSid()) {
             return SAVED_UPDATED;
         } else {
             return parent::save();
         }
     } else {
         // Update the transition.
         return parent::save();
     }
 }

作者:aritnath199    项目:simplenewslates   
/**
  * {@inheritdoc}
  */
 public function postCreate(EntityStorageInterface $storage)
 {
     parent::postCreate($storage);
     // Set the uid field if there is a user with the same email.
     $user_ids = \Drupal::entityQuery('user')->condition('mail', $this->getMail())->execute();
     if (!empty($user_ids)) {
         $this->setUserId(array_pop($user_ids));
     }
     // Copy values for shared fields from existing user.
     if (\Drupal::config('simplenews.settings')->get('subscriber.sync_fields') && ($user = $this->getUser())) {
         foreach ($this->getUserSharedFields($user) as $field_name) {
             $this->set($field_name, $user->get($field_name)->getValue());
         }
     }
 }

作者:anatalsce    项目:en-class   
/**
  * {@inheritdoc}
  */
 public static function preDelete(EntityStorageInterface $storage, array $entities)
 {
     parent::preDelete($storage, $entities);
     foreach ($entities as $entity) {
         // Delete all remaining references to this file.
         $file_usage = \Drupal::service('file.usage')->listUsage($entity);
         if (!empty($file_usage)) {
             foreach ($file_usage as $module => $usage) {
                 \Drupal::service('file.usage')->delete($entity, $module);
             }
         }
         // Delete the actual file. Failures due to invalid files and files that
         // were already deleted are logged to watchdog but ignored, the
         // corresponding file entity will be deleted.
         file_unmanaged_delete($entity->getFileUri());
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号