本文整理汇总了PHP中Drupal\Core\Entity\ContentEntityBase类的典型用法代码示例。如果您正苦于以下问题:PHP ContentEntityBase类的具体用法?PHP ContentEntityBase怎么用?PHP ContentEntityBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContentEntityBase类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:eigentor,项目名称:tommiblog,代码行数:13,代码来源:FieldRdfaTestBase.php
示例2: preCreate
/**
* {@inheritdoc}
*/
public static function preCreate(EntityStorageInterface $storage, array &$values)
{
parent::preCreate($storage, $values);
if (empty($values['type'])) {
$values['type'] = $storage->getEntityTypeId();
}
}
开发者ID:ddrozdik,项目名称:dmaps,代码行数:10,代码来源:EntityTest.php
示例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());
}
}
开发者ID:marmouset,项目名称:drupal,代码行数:11,代码来源:Store.php
示例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;
}
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:11,代码来源:EntityTest.php
示例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;
}
开发者ID:malcomio,项目名称:drupalytics,代码行数:12,代码来源:CheckstyleIssue.php
示例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();
}
}
开发者ID:pedrocones,项目名称:hydrotools,代码行数:12,代码来源:Order.php
示例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();
}
}
开发者ID:heddn,项目名称:content_entity_base,代码行数:13,代码来源:EntityBase.php
示例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);
}
}
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:13,代码来源:Term.php
示例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());
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:14,代码来源:ContentEntityBaseUnitTest.php
示例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.');
}
}
开发者ID:HakS,项目名称:drupal8_training,代码行数:14,代码来源:EntitySerializationTest.php
示例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);
}
开发者ID:pedrocones,项目名称:hydrotools,代码行数:19,代码来源:CartItem.php
示例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();
}
}
}
开发者ID:marmouset,项目名称:drupal,代码行数:19,代码来源:Order.php
示例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);
}
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:9,代码来源:User.php
示例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);
}
}
开发者ID:shumer,项目名称:blog,代码行数:13,代码来源:MenuLinkContent.php
示例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);
}
开发者ID:brstde,项目名称:gap1,代码行数:10,代码来源:Node.php
示例16: postDelete
/**
* {@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));
}
}
}
开发者ID:papillon-cendre,项目名称:d8,代码行数:15,代码来源:Feed.php
示例17: postSave
/**
* {@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();
}
}
}
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:15,代码来源:Product.php
示例18: save
/**
* 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();
}
}
开发者ID:sedurzu,项目名称:ildeposito8,代码行数:48,代码来源:WorkflowTransition.php
示例19: postCreate
/**
* {@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());
}
}
}
开发者ID:aritnath1990,项目名称:simplenewslatest,代码行数:18,代码来源:Subscriber.php
示例20: preDelete
/**
* {@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());
}
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:20,代码来源:File.php
注:本文中的Drupal\Core\Entity\ContentEntityBase类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论