本文整理汇总了PHP中Drupal\Core\Entity\EntityManagerInterface::getStorage方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManagerInterface::getStorage方法的具体用法?PHP EntityManagerInterface::getStorage怎么用?PHP EntityManagerInterface::getStorage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::getStorage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state)
{
$forum_config = $this->config('forum.settings');
$vid = $forum_config->get('vocabulary');
$vocabulary = $this->entityManager->getStorage('taxonomy_vocabulary')->load($vid);
if (!$vocabulary) {
throw new NotFoundHttpException();
}
// Build base taxonomy term overview.
$form = parent::buildForm($form, $form_state, $vocabulary);
foreach (Element::children($form['terms']) as $key) {
if (isset($form['terms'][$key]['#term'])) {
$term = $form['terms'][$key]['#term'];
$form['terms'][$key]['term']['#url'] = Url::fromRoute('forum.page', ['taxonomy_term' => $term->id()]);
unset($form['terms'][$key]['operations']['#links']['delete']);
$route_parameters = $form['terms'][$key]['operations']['#links']['edit']['url']->getRouteParameters();
if (!empty($term->forum_container->value)) {
$form['terms'][$key]['operations']['#links']['edit']['title'] = $this->t('edit container');
$form['terms'][$key]['operations']['#links']['edit']['url'] = Url::fromRoute('entity.taxonomy_term.forum_edit_container_form', $route_parameters);
} else {
$form['terms'][$key]['operations']['#links']['edit']['title'] = $this->t('edit forum');
$form['terms'][$key]['operations']['#links']['edit']['url'] = Url::fromRoute('entity.taxonomy_term.forum_edit_form', $route_parameters);
}
// We don't want the redirect from the link so we can redirect the
// delete action.
unset($form['terms'][$key]['operations']['#links']['edit']['query']['destination']);
}
}
// Remove the alphabetical reset.
unset($form['actions']['reset_alphabetical']);
// Use the existing taxonomy overview submit handler.
$form['terms']['#empty'] = $this->t('No containers or forums available. <a href="@container">Add container</a> or <a href="@forum">Add forum</a>.', array('@container' => $this->url('forum.add_container'), '@forum' => $this->url('forum.add_forum')));
return $form;
}
示例2: convert
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults, Request $request)
{
$entity_type = substr($definition['type'], strlen('entity:'));
if ($storage = $this->entityManager->getStorage($entity_type)) {
return $storage->load($value);
}
}
示例3: autocomplete
/**
* Handles the response for inline entity form autocompletion.
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function autocomplete($entity_type_id, $field_name, $bundle, Request $request)
{
$string = $request->query->get('q');
$fields = $this->entityManager->getFieldDefinitions($entity_type_id, $bundle);
$widget = $this->entityManager->getStorage('entity_form_display')->load($entity_type_id . '.' . $bundle . '.default')->getComponent($field_name);
// The path was passed invalid parameters, or the string is empty.
// strlen() is used instead of empty() since '0' is a valid value.
if (!isset($fields[$field_name]) || !$widget || !strlen($string)) {
throw new AccessDeniedHttpException();
}
$field = $fields[$field_name];
$results = array();
if ($field->getType() == 'entity_reference') {
/** @var \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface $handler */
$handler = $this->selectionManager->getSelectionHandler($field);
$entity_labels = $handler->getReferenceableEntities($string, $widget['settings']['match_operator'], 10);
foreach ($entity_labels as $bundle => $labels) {
// Loop through each entity type, and autocomplete with its titles.
foreach ($labels as $entity_id => $label) {
// entityreference has already check_plain-ed the title.
$results[] = t('!label (!entity_id)', array('!label' => $label, '!entity_id' => $entity_id));
}
}
}
$matches = array();
foreach ($results as $result) {
// Strip things like starting/trailing white spaces, line breaks and tags.
$key = preg_replace('/\\s\\s+/', ' ', str_replace("\n", '', trim(Html::decodeEntities(strip_tags($result)))));
$matches[] = ['value' => $key, 'label' => '<div class="reference-autocomplete">' . $result . '</div>'];
}
return new JsonResponse($matches);
}
示例4: __construct
/**
* Creates a NodeBlock instance.
*
* @param array $configuration
* @param string $plugin_id
* @param mixed $plugin_definition
* @param EntityManagerInterface $entity_manager
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager)
{
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->viewBuilder = $entity_manager->getViewBuilder('node');
$this->nodeStorage = $entity_manager->getStorage('node');
$this->node = $entity_manager->getStorage('node')->load($this->getDerivativeId());
}
示例5: getMatches
/**
* Returns matched labels based on a given field, instance and search string.
*
* This function can be used by other modules that wish to pass a mocked
* definition of the field on instance.
*
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
* The field definition.
* @param string $entity_type
* The entity type.
* @param string $bundle
* The entity bundle.
* @param string $entity_id
* (optional) The entity ID the entity reference field is attached to.
* Defaults to ''.
* @param string $prefix
* (optional) A prefix for all the keys returned by this function.
* @param string $string
* (optional) The label of the entity to query by.
*
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
* Thrown when the current user doesn't have access to the specifies entity.
*
* @return array
* A list of matched entity labels.
*
* @see \Drupal\entity_reference\EntityReferenceController
*/
public function getMatches(FieldDefinitionInterface $field_definition, $entity_type, $bundle, $entity_id = '', $prefix = '', $string = '')
{
$matches = array();
$entity = NULL;
if ($entity_id !== 'NULL') {
$entity = $this->entityManager->getStorage($entity_type)->load($entity_id);
if (!$entity || !$entity->access('view')) {
throw new AccessDeniedHttpException();
}
}
$handler = $this->selectionHandlerManager->getSelectionHandler($field_definition, $entity);
if (isset($string)) {
// Get an array of matching entities.
$widget = entity_get_form_display($entity_type, $bundle, 'default')->getComponent($field_definition->getName());
$match_operator = !empty($widget['settings']['match_operator']) ? $widget['settings']['match_operator'] : 'CONTAINS';
$entity_labels = $handler->getReferenceableEntities($string, $match_operator, 10);
// Loop through the entities and convert them into autocomplete output.
foreach ($entity_labels as $values) {
foreach ($values as $entity_id => $label) {
$key = "{$label} ({$entity_id})";
// Strip things like starting/trailing white spaces, line breaks and
// tags.
$key = preg_replace('/\\s\\s+/', ' ', str_replace("\n", '', trim(decode_entities(strip_tags($key)))));
// Names containing commas or quotes must be wrapped in quotes.
$key = Tags::encode($key);
$matches[] = array('value' => $prefix . $key, 'label' => $label);
}
}
}
return $matches;
}
示例6: setUp
/**
* {@inheritdoc}
*
* @covers ::__construct
*/
protected function setUp()
{
$this->pageStorage = $this->prophesize(ConfigEntityStorageInterface::class);
$this->entityManager = $this->prophesize(EntityManagerInterface::class);
$this->entityManager->getStorage('page')->willReturn($this->pageStorage);
$this->routeSubscriber = new PageManagerRoutes($this->entityManager->reveal());
}
示例7: validateAndUpcastRequestAttributes
/**
* Validates and upcasts request attributes.
*
* @todo Remove once https://drupal.org/node/1837388 is fixed.
*/
protected function validateAndUpcastRequestAttributes(Request $request)
{
// Load the entity.
if (!is_object($entity = $request->attributes->get('entity'))) {
$entity_id = $entity;
$entity_type = $request->attributes->get('entity_type');
if (!$entity_type || !$this->entityManager->getDefinition($entity_type)) {
return FALSE;
}
$entity = $this->entityManager->getStorage($entity_type)->load($entity_id);
if (!$entity) {
return FALSE;
}
$request->attributes->set('entity', $entity);
}
// Validate the field name and language.
$field_name = $request->attributes->get('field_name');
if (!$field_name || !$entity->hasField($field_name)) {
return FALSE;
}
$langcode = $request->attributes->get('langcode');
if (!$langcode || !$entity->hasTranslation($langcode)) {
return FALSE;
}
return TRUE;
}
示例8: routes
/**
* Returns an array of route objects.
*
* @return \Symfony\Component\Routing\Route[]
* An array of route objects.
*/
public function routes()
{
$routes = array();
$is_multilingual = $this->languageManager->isMultilingual();
/* @var $search_api_page \Drupal\search_api_page\SearchApiPageInterface */
foreach ($this->entityManager->getStorage('search_api_page')->loadMultiple() as $search_api_page) {
// Default path.
$default_path = $search_api_page->getPath();
// Loop over all languages so we can get the translated path (if any).
foreach ($this->languageManager->getLanguages() as $language) {
// Check if we are multilingual or not.
if ($is_multilingual) {
$path = $this->languageManager->getLanguageConfigOverride($language->getId(), 'search_api_page.search_api_page.' . $search_api_page->id())->get('path');
}
if (empty($path)) {
$path = $default_path;
}
$args = ['_controller' => 'Drupal\\search_api_page\\Controller\\SearchApiPageController::page', 'search_api_page_name' => $search_api_page->id()];
// Use clean urls or not.
if ($search_api_page->getCleanUrl()) {
$path .= '/{keys}';
$args['keys'] = '';
}
$routes['search_api_page.' . $language->getId() . '.' . $search_api_page->id()] = new Route($path, $args, array('_permission' => 'view search api pages'));
}
}
return $routes;
}
示例9: collect
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = NULL)
{
$views = $this->view_executable_factory->getViews();
$storage = $this->entityManager->getStorage('view');
/** @var TraceableViewExecutable $view */
foreach ($views as $view) {
if ($view->executed) {
$data = ['id' => $view->storage->id(), 'current_display' => $view->current_display, 'build_time' => $view->getBuildTime(), 'execute_time' => $view->getExecuteTime(), 'render_time' => $view->getRenderTime()];
$entity = $storage->load($view->storage->id());
if ($entity->hasLinkTemplate('edit-display-form')) {
$route = $entity->urlInfo('edit-display-form');
$route->setRouteParameter('display_id', $view->current_display);
$data['route'] = $route->toString();
}
$this->data['views'][] = $data;
}
}
// TODO: also use those data.
// $loaded = $this->entityManager->getLoaded('view');
//
// if ($loaded) {
// /** @var \Drupal\webprofiler\Entity\EntityStorageDecorator $views */
// foreach ($loaded->getEntities() as $views) {
// $this->data['views'][] = array(
// 'id' => $views->get('id'),
// );
// }
// }
}
示例10: build
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match)
{
$breadcrumb[] = Link::createFromRoute($this->t('Home'), '<front>');
$vocabulary = $this->entityManager->getStorage('taxonomy_vocabulary')->load($this->config->get('vocabulary'));
$breadcrumb[] = Link::createFromRoute($vocabulary->label(), 'forum.index');
return $breadcrumb;
}
示例11: getDescription
/**
* {@inheritdoc}
*/
public function getDescription()
{
$locked = $this->tempStore->getMetadata($this->entity->id());
$account = $this->entityManager->getStorage('user')->load($locked->owner);
$username = array('#theme' => 'username', '#account' => $account);
return $this->t('By breaking this lock, any unsaved changes made by @user will be lost.', array('@user' => drupal_render($username)));
}
示例12: settingsForm
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, FormStateInterface $form_state)
{
$options = [];
foreach ($this->entityManager->getStorage('image_style')->loadMultiple() as $id => $image_style) {
$options[$id] = $image_style->label();
}
return ['image_style' => ['#type' => 'select', '#title' => t('Image style'), '#description' => t('Select image style to be used to display thumbnails.'), '#default_value' => $this->configuration['image_style'], '#options' => $options]];
}
示例13: build
/**
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match)
{
$breadcrumb = array();
$breadcrumb[] = $this->l($this->t('Home'), '<front>');
$entity = $this->entityManager->getStorage($route_match->getParameter('entity_type'))->load($route_match->getParameter('entity_id'));
$breadcrumb[] = \Drupal::linkGenerator()->generateFromUrl($entity->label(), $entity->urlInfo());
return $breadcrumb;
}
示例14: permissions
/**
* Get taxonomy permissions.
*
* @return array
* Permissions array.
*/
public function permissions()
{
$permissions = [];
foreach ($this->entityManager->getStorage('taxonomy_vocabulary')->loadMultiple() as $vocabulary) {
$permissions += ['edit terms in ' . $vocabulary->id() => ['title' => $this->t('Edit terms in %vocabulary', ['%vocabulary' => $vocabulary->label()])]];
$permissions += ['delete terms in ' . $vocabulary->id() => ['title' => $this->t('Delete terms from %vocabulary', ['%vocabulary' => $vocabulary->label()])]];
}
return $permissions;
}
示例15: routes
/**
* Returns an array of route objects.
*
* @return \Symfony\Component\Routing\Route[]
* An array of route objects.
*/
public function routes()
{
$routes = array();
/** @var $searchApiPage SearchApiPageInterface */
foreach ($this->entityManager->getStorage('search_api_page')->loadMultiple() as $searchApiPage) {
$routes['search_api_page.' . $searchApiPage->id()] = new Route('/' . $searchApiPage->getPath() . '/{keyword}', array('_controller' => 'Drupal\\search_api_page\\Controller\\SearchApiPageController::page', 'search_api_page' => $searchApiPage->id(), 'keyword' => ''), array('_access' => 'TRUE'));
}
return $routes;
}