本文整理匯總了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();
}