本文整理汇总了PHP中Drupal\Core\Entity\EntityManagerInterface::loadEntityByUuid方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManagerInterface::loadEntityByUuid方法的具体用法?PHP EntityManagerInterface::loadEntityByUuid怎么用?PHP EntityManagerInterface::loadEntityByUuid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::loadEntityByUuid方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* {@inheritdoc}
*/
public function process($text, $langcode)
{
$result = new FilterProcessResult($text);
if (stristr($text, 'data-entity-type="file"') !== FALSE) {
$dom = Html::load($text);
$xpath = new \DOMXPath($dom);
$processed_uuids = array();
foreach ($xpath->query('//*[@data-entity-type="file" and @data-entity-uuid]') as $node) {
$uuid = $node->getAttribute('data-entity-uuid');
// If there is a 'src' attribute, set it to the file entity's current
// URL. This ensures the URL works even after the file location changes.
if ($node->hasAttribute('src')) {
$file = $this->entityManager->loadEntityByUuid('file', $uuid);
if ($file) {
$node->setAttribute('src', file_url_transform_relative(file_create_url($file->getFileUri())));
}
}
// Only process the first occurrence of each file UUID.
if (!isset($processed_uuids[$uuid])) {
$processed_uuids[$uuid] = TRUE;
$file = $this->entityManager->loadEntityByUuid('file', $uuid);
if ($file) {
$result->addCacheTags($file->getCacheTags());
}
}
}
$result->setProcessedText(Html::serialize($dom));
}
return $result;
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, PageInterface $page = NULL, $name = '')
{
$this->page = $page;
$this->staticContext = $this->page->getStaticContext($name);
// Allow the condition to add to the form.
$form['label'] = ['#type' => 'textfield', '#title' => $this->t('Label'), '#default_value' => isset($this->staticContext['label']) ? $this->staticContext['label'] : '', '#required' => TRUE];
$form['machine_name'] = ['#type' => 'machine_name', '#maxlength' => 64, '#required' => TRUE, '#machine_name' => ['exists' => [$this, 'contextExists'], 'source' => ['label']], '#default_value' => $name];
$form['entity_type'] = ['#type' => 'select', '#title' => $this->t('Entity type'), '#options' => $this->entityManager->getEntityTypeLabels(TRUE), '#limit_validation_errors' => array(array('entity_type')), '#submit' => ['::rebuildSubmit'], '#executes_submit_callback' => TRUE, '#ajax' => array('callback' => '::updateEntityType', 'wrapper' => 'add-static-context-wrapper', 'method' => 'replace')];
$entity = NULL;
if ($form_state->hasValue('entity_type')) {
$entity_type = $form_state->getValue('entity_type');
if ($this->staticContext['value']) {
$entity = $this->entityManager->loadEntityByUuid($entity_type, $this->staticContext['value']);
}
} elseif (!empty($this->staticContext['type'])) {
list(, $entity_type) = explode(':', $this->staticContext['type']);
$entity = $this->entityManager->loadEntityByUuid($entity_type, $this->staticContext['value']);
} elseif ($this->entityManager->hasDefinition('node')) {
$entity_type = 'node';
} else {
$entity_type = 'user';
}
$form['entity_type']['#default_value'] = $entity_type;
$form['selection'] = ['#type' => 'entity_autocomplete', '#prefix' => '<div id="add-static-context-wrapper">', '#suffix' => '</div>', '#required' => TRUE, '#target_type' => $entity_type, '#default_value' => $entity, '#title' => $this->t('Select entity')];
$form['actions'] = ['#type' => 'actions'];
$form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->submitButtonText(), '#button_type' => 'primary'];
return $form;
}
示例3: getContextValue
/**
* {@inheritdoc}
*/
public function getContextValue()
{
if (!$this->contextValue) {
$entity_type_id = substr($this->contextDefinition->getDataType(), 7);
$this->contextValue = $this->entityManager->loadEntityByUuid($entity_type_id, $this->uuid);
}
return $this->contextValue;
}
示例4: resolve
/**
* {@inheritdoc}
*/
public function resolve(NormalizerInterface $normalizer, $data, $entity_type)
{
// The normalizer is what knows the specification of the data being
// deserialized. If it can return a UUID from that data, and if there's an
// entity with that UUID, then return its ID.
if ($normalizer instanceof UuidReferenceInterface && ($uuid = $normalizer->getUuid($data))) {
if ($entity = $this->entityManager->loadEntityByUuid($entity_type, $uuid)) {
return $entity->id();
}
}
return NULL;
}
示例5: getEntity
/**
* Loads the block content entity of the block.
*
* @return \Drupal\block_content\BlockContentInterface|null
* The block content entity.
*/
protected function getEntity()
{
$uuid = $this->getDerivativeId();
if (!isset($this->blockContent)) {
$this->blockContent = $this->entityManager->loadEntityByUuid('block_content', $uuid);
}
return $this->blockContent;
}
示例6: build
/**
* {@inheritdoc}
*/
public function build()
{
$uuid = $this->getDerivativeId();
if ($block = $this->entityManager->loadEntityByUuid('block_content', $uuid)) {
return $this->entityManager->getViewBuilder($block->getEntityTypeId())->view($block, $this->configuration['view_mode']);
} else {
return array('#markup' => $this->t('Block with uuid %uuid does not exist. <a href="!url">Add custom block</a>.', array('%uuid' => $uuid, '!url' => $this->urlGenerator->generate('block_content.add_page'))), '#access' => $this->account->hasPermission('administer blocks'));
}
}
示例7: process
/**
* {@inheritdoc}
*/
public function process($text, $langcode)
{
$result = new FilterProcessResult($text);
if (stristr($text, 'data-entity-type="file"') !== FALSE) {
$dom = Html::load($text);
$xpath = new \DOMXPath($dom);
$processed_uuids = array();
foreach ($xpath->query('//*[@data-entity-type="file" and @data-entity-uuid]') as $node) {
$uuid = $node->getAttribute('data-entity-uuid');
// Only process the first occurrence of each file UUID.
if (!isset($processed_uuids[$uuid])) {
$processed_uuids[$uuid] = TRUE;
$file = $this->entityManager->loadEntityByUuid('file', $uuid);
if ($file) {
$result->addCacheTags($file->getCacheTags());
}
}
}
}
return $result;
}
示例8: findMissingContentDependencies
/**
* {@inheritdoc}
*/
public function findMissingContentDependencies()
{
$content_dependencies = array();
$missing_dependencies = array();
foreach ($this->activeStorage->readMultiple($this->activeStorage->listAll()) as $config_data) {
if (isset($config_data['dependencies']['content'])) {
$content_dependencies = array_merge($content_dependencies, $config_data['dependencies']['content']);
}
}
foreach (array_unique($content_dependencies) as $content_dependency) {
// Format of the dependency is entity_type:bundle:uuid.
list($entity_type, $bundle, $uuid) = explode(':', $content_dependency, 3);
if (!$this->entityManager->loadEntityByUuid($entity_type, $uuid)) {
$missing_dependencies[$uuid] = array('entity_type' => $entity_type, 'bundle' => $bundle, 'uuid' => $uuid);
}
}
return $missing_dependencies;
}
示例9: loadEntityByUuid
/**
* {@inheritdoc}
*/
public function loadEntityByUuid($entity_type_id, $uuid)
{
return $this->entityManager->loadEntityByUuid($entity_type_id, $uuid);
}