本文整理汇总了PHP中Drupal\Core\Entity\EntityInterface::getFileUri方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface::getFileUri方法的具体用法?PHP EntityInterface::getFileUri怎么用?PHP EntityInterface::getFileUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityInterface
的用法示例。
在下文中一共展示了EntityInterface::getFileUri方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: view
/**
* {@inheritdoc}
*/
public function view(EntityInterface $entity)
{
if ($entity instanceof FileInterface) {
return ['#theme' => 'image_style', '#style_name' => $this->configuration['image_style'], '#title' => $entity->label(), '#alt' => $entity->label(), '#uri' => $entity->getFileUri()];
}
return $entity->label();
}
示例2: checkAccess
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account)
{
/** @var \Drupal\file\FileInterface $entity */
if ($operation == 'download' || $operation == 'view') {
if (\Drupal::service('file_system')->uriScheme($entity->getFileUri()) === 'public') {
// Always allow access to file in public file system.
return AccessResult::allowed();
} elseif ($references = $this->getFileReferences($entity)) {
foreach ($references as $field_name => $entity_map) {
foreach ($entity_map as $referencing_entity_type => $referencing_entities) {
/** @var \Drupal\Core\Entity\EntityInterface $referencing_entity */
foreach ($referencing_entities as $referencing_entity) {
$entity_and_field_access = $referencing_entity->access('view', $account, TRUE)->andIf($referencing_entity->{$field_name}->access('view', $account, TRUE));
if ($entity_and_field_access->isAllowed()) {
return $entity_and_field_access;
}
}
}
}
} elseif ($entity->getOwnerId() == $account->id()) {
// This case handles new nodes, or detached files. The user who uploaded
// the file can always access if it's not yet used.
return AccessResult::allowed();
}
}
// No opinion.
return AccessResult::neutral();
}
示例3: uri
/**
* {@inheritdoc}
*/
public function uri(EntityInterface $entity) {
/** @var \Drupal\file\FileInterface $entity */
return $entity->getFileUri();
}