本文整理汇总了PHP中Drupal\Core\Entity\ContentEntityBase类的典型用法代码示例。如果您正苦于以下问题:PHP ContentEntityBase类的具体用法?PHP ContentEntityBase怎么用?PHP ContentEntityBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContentEntityBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAbsoluteUri
/**
* 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));
}
示例2: preCreate
/**
* {@inheritdoc}
*/
public static function preCreate(EntityStorageInterface $storage, array &$values)
{
parent::preCreate($storage, $values);
if (empty($values['type'])) {
$values['type'] = $storage->getEntityTypeId();
}
}
示例3: preSave
/**
* {@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());
}
}
示例4: baseFieldDefinitions
/**
* {@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;
}
示例5: preCreate
/**
* {@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;
}
示例6: postLoad
/**
* {@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();
}
}
示例7: preSaveRevision
/**
* {@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();
}
}
示例8: postSave
/**
* {@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);
}
}
示例9: testLabel
/**
* @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());
}
示例10: testDenormalize
/**
* 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.');
}
}
示例11: postLoad
/**
* {@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);
}
示例12: postSave
/**
* {@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();
}
}
}
示例13: postDelete
/**
* {@inheritdoc}
*/
public static function postDelete(EntityStorageInterface $storage, array $entities)
{
parent::postDelete($storage, $entities);
$uids = array_keys($entities);
\Drupal::service('user.data')->delete(NULL, $uids);
}
示例14: preDelete
/**
* {@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);
}
}
示例15: access
/**
* {@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);
}