本文整理汇总了PHP中entity_view函数的典型用法代码示例。如果您正苦于以下问题:PHP entity_view函数的具体用法?PHP entity_view怎么用?PHP entity_view使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了entity_view函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processCallback
/**
* Callback for preg_replace in process()
*/
public static function processCallback($matches = array())
{
$content = '';
$entity_type = $entity_id = $view_mode = '';
foreach ($matches as $key => $match) {
switch ($key) {
case 1:
$entity_type = $match;
break;
case 2:
$entity_id = $match;
break;
case 3:
$view_mode = $match;
break;
}
}
$entities = entity_load($entity_type, array($entity_id));
if (!empty($entities)) {
$render_array = entity_view($entity_type, $entities, $view_mode, NULL, TRUE);
// Remove contextual links.
if (isset($render_array[$entity_type][$entity_id]['#contextual_links'])) {
unset($render_array[$entity_type][$entity_id]['#contextual_links']);
}
$content = render($render_array);
}
return $content;
}
示例2: nodeMarkup
/**
* Lists all instances of fields on any views.
*
* @return array
* The Views fields report page.
*/
public function nodeMarkup($node, $key = 'default') {
$node = Node::load($node);
$builded_entity = entity_view($node, $key);
$markup = drupal_render($builded_entity);
$links = array();
$links['default'] = array(
'title' => 'Default',
'url' => Url::fromRoute('ds_devel.markup', array('node' => $node->id())),
);
$view_modes = \Drupal::entityManager()->getViewModes('node');
foreach ($view_modes as $id => $info) {
if (!empty($info['status'])) {
$links[] = array(
'title' => $info['label'],
'url' => Url::fromRoute('ds_devel.markup_view_mode', array('node' => $node->id(), 'key' => $id)),
);
}
}
$build['links'] = array(
'#theme' => 'links',
'#links' => $links,
'#prefix' => '<div>',
'#suffix' => '</div><hr />',
);
$build['markup'] = [
'#markup' => '<code><pre>' . Html::escape($markup) . '</pre></code>',
'#allowed_tags' => ['code', 'pre'],
];
return $build;
}
示例3: testWhosOnlineBlock
/**
* Test the Who's Online block.
*/
function testWhosOnlineBlock()
{
$block = $this->drupalPlaceBlock('views_block:who_s_online-who_s_online_block');
// Generate users.
$user1 = $this->drupalCreateUser(array('access user profiles'));
$user2 = $this->drupalCreateUser(array());
$user3 = $this->drupalCreateUser(array());
// Update access of two users to be within the active timespan.
$this->updateAccess($user1->id());
$this->updateAccess($user2->id(), REQUEST_TIME + 1);
// Insert an inactive user who should not be seen in the block, and ensure
// that the admin user used in setUp() does not appear.
$inactive_time = REQUEST_TIME - 15 * 60 - 1;
$this->updateAccess($user3->id(), $inactive_time);
$this->updateAccess($this->adminUser->id(), $inactive_time);
// Test block output.
\Drupal::currentUser()->setAccount($user1);
$content = entity_view($block, 'block');
$this->drupalSetContent(render($content));
$this->assertRaw(t('2 users'), 'Correct number of online users (2 users).');
$this->assertText($user1->getUsername(), 'Active user 1 found in online list.');
$this->assertText($user2->getUsername(), 'Active user 2 found in online list.');
$this->assertNoText($user3->getUsername(), 'Inactive user not found in online list.');
$this->assertTrue(strpos($this->drupalGetContent(), $user1->getUsername()) > strpos($this->drupalGetContent(), $user2->getUsername()), 'Online users are ordered correctly.');
}
示例4: gitp_preprocess_node__blog
function gitp_preprocess_node__blog(&$variables)
{
$author_uid = $variables['uid'];
$author = profile2_load_by_user($author_uid);
$variables['author_thumbnail_profile'] = entity_view('profile2', $author, 'thumbnail_profile');
$variables['author_profile'] = entity_view('profile2', $author, 'author_profile');
}
示例5: viewElements
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items)
{
$view_mode = $this->getSetting('view_mode');
$elements = array();
foreach ($this->getEntitiesToView($items) as $delta => $entity) {
// Protect ourselves from recursive rendering.
static $depth = 0;
$depth++;
if ($depth > 20) {
throw new RecursiveRenderingException(format_string('Recursive rendering detected when rendering entity @entity_type(@entity_id). Aborting rendering.', array('@entity_type' => $entity->getEntityTypeId(), '@entity_id' => $entity->id())));
}
if ($entity->id()) {
$elements[$delta] = entity_view($entity, $view_mode, $entity->language()->getId());
// Add a resource attribute to set the mapping property's value to the
// entity's url. Since we don't know what the markup of the entity will
// be, we shouldn't rely on it for structured data such as RDFa.
if (!empty($items[$delta]->_attributes)) {
$items[$delta]->_attributes += array('resource' => $entity->url());
}
} else {
// This is an "auto_create" item.
$elements[$delta] = array('#markup' => $entity->label());
}
$depth = 0;
}
return $elements;
}
示例6: testBasicRendering
/**
* Tests the rendering of blocks.
*/
public function testBasicRendering()
{
\Drupal::state()->set('block_test.content', '');
$entity = $this->controller->create(array('id' => 'test_block1', 'theme' => 'stark', 'plugin' => 'test_html'));
$entity->save();
// Test the rendering of a block.
$entity = Block::load('test_block1');
$output = entity_view($entity, 'block');
$expected = array();
$expected[] = '<div id="block-test-block1">';
$expected[] = ' ';
$expected[] = ' ';
$expected[] = ' ';
$expected[] = ' </div>';
$expected[] = '';
$expected_output = implode("\n", $expected);
$this->assertEqual($this->renderer->renderRoot($output), $expected_output);
// Reset the HTML IDs so that the next render is not affected.
Html::resetSeenIds();
// Test the rendering of a block with a given title.
$entity = $this->controller->create(array('id' => 'test_block2', 'theme' => 'stark', 'plugin' => 'test_html', 'settings' => array('label' => 'Powered by Bananas')));
$entity->save();
$output = entity_view($entity, 'block');
$expected = array();
$expected[] = '<div id="block-test-block2">';
$expected[] = ' ';
$expected[] = ' <h2>Powered by Bananas</h2>';
$expected[] = ' ';
$expected[] = ' ';
$expected[] = ' </div>';
$expected[] = '';
$expected_output = implode("\n", $expected);
$this->assertEqual($this->renderer->renderRoot($output), $expected_output);
}
示例7: hook_commerce_search_index_product
/**
* Returns text for a product to be indexed as search keywords.
*
* @param $product stdClass The commerce_product to be indexed.
*
* @return String|Array The keywords to be indexed.
*/
function hook_commerce_search_index_product($product)
{
$keywords = explode('-', $product->sku);
$renderable = entity_view('commerce_product', array($product), 'node_search_index');
$keywords[] = drupal_render($renderable);
return $keywords;
}
示例8: content_ajax_page_fc
private function content_ajax_page_fc($fcid)
{
$fcitem = \Drupal\field_collection\Entity\FieldCollectionItem::load($fcid);
$target = WG::entity_get_field_value($fcitem, 'field_target');
preg_match('%^([^:]+)://([0-9]+)$%', $target, $m);
$itemtype = $m[1];
$id = $m[2];
switch ($itemtype) {
case 'public318':
$identifier = $id;
$text = WG::entity_get_field_formatted_text($fcitem, 'field_annotation');
$stylename = 'large';
$icon_uri = _expo_public318_get_icon_uri($identifier);
$icontag = WG::render_styled_image($icon_uri, $stylename);
$output = '<div class="sticky-fc-public318">' . '<div class="collicon">' . _expo_coll_url($identifier, $icontag) . '</div>' . '<div class="colltext">' . $text . '</div>' . '</div>';
break;
case 'storynode':
$nid = $id;
$story = node_load($nid);
$v = entity_view($story, 'ajaxpage');
$output = render($v);
break;
default:
$tag = "<div class=\"sticky\" id=\"sticky_{$pos}\">" . $itemtype . $pos . "</div>";
}
$build = ['#markup' => $output];
return $build;
}
示例9: build
/**
* {@inheritdoc}
*/
public function build()
{
$nid = self::_gen_random_nid();
$node = node_load($nid);
$v = entity_view($node, 'full');
$build = ['#markup' => render($v), '#cache' => ['max-age' => 0]];
return $build;
}
示例10: viewAction
/**
* @Route("/{entity_type}/{entity}", name="entity_view", defaults={"view_mode" = "full", "langcode" = null, "page" = null})
* @Method("GET")
* @ParamConverter("entity", converter="drupal.entity")
* @Template
*/
public function viewAction(Request $request, $entity_type, $entity)
{
$view_mode = $request->get('view_mode');
$langcode = $request->get('langcode');
$page = $request->get('page');
list($id, $vid, $bundle) = entity_extract_ids($entity_type, $entity);
$entities = entity_view($entity_type, array($id => $entity), $view_mode, $langcode, $page);
return array('label' => entity_label($entity_type, $entity), 'uri' => entity_uri($entity_type, $entity), 'entity_type' => $entity_type, 'id' => $id, 'vid' => $vid, 'bundle' => $bundle, 'entity' => $entity, 'content' => reset($entities[$entity_type]));
}
示例11: build
/**
* {@inheritdoc}
*/
public function build()
{
$view_mode = $this->getEntityViewMode();
/** @var $comment CommentInterface */
$comment = $this->entity();
$uid = $comment->getOwnerId();
$user = entity_load('user', $uid);
$build = entity_view($user, $view_mode);
return $build;
}
示例12: entityView
/**
* {@inheritdoc}
*/
public function entityView()
{
$configuration = $this->getConfiguration();
if ($node = $this->entityLoad()) {
if ($this->entityAccess()) {
return entity_view($this->getType(), array($this->getEntity()), $configuration['view mode']);
}
}
return FALSE;
}
示例13: render
/**
* {@inheritdoc}
*/
public function render($empty = FALSE)
{
if (!$empty || !empty($this->options['empty'])) {
$entity_id = $this->tokenizeValue($this->options['entity_id']);
$entity = entity_load($this->entityType, $entity_id);
if ($entity && (!empty($this->options['bypass_access']) || $entity->access('view'))) {
return entity_view($entity, $this->options['view_mode']);
}
}
return array();
}
示例14: switchViewMode
/**
* Returns an node through JSON.
*
* @param Request $request
* The global request object.
* @param string $entityType
* The type of the requested entity.
* @param string $entityId
* The id of the requested entity.
* @param string $viewMode
* The view mode you wish to render for the requested entity.
*
* @return array
* The Views fields report page.
*/
public function switchViewMode(Request $request, $entityType, $entityId, $viewMode)
{
$response = new AjaxResponse();
$entity = entity_load($entityType, $entityId);
if ($entity->access('view')) {
$element = entity_view($entity, $viewMode);
$content = \Drupal::service('renderer')->render($element, FALSE);
$response->addCommand(new ReplaceCommand('.' . $request->get('selector'), $content));
}
return $response;
}
示例15: view
/**
* Displays the bean.
*/
public function view($bean, $content, $view_mode = 'default', $langcode = NULL)
{
// Retrieve the terms from the loaded entity.
$active_entity = bean_tax_active_entity_array();
// Check for cached content on this block.
$cache_name = 'bean_tax:listing:' . $bean->delta . ':' . $active_entity['type'] . ':' . $active_entity['ids'][0];
if ($cache = cache_get($cache_name)) {
$content = $cache->data;
} else {
// We need to make sure that the bean is configured correctly.
if ($active_entity['type'] != 'bean' && !empty($bean->filters['vocabulary']) && (isset($active_entity['terms']) && count($active_entity['terms']))) {
// Reformat vocabulary list from machine names to vocabulary vids.
$vids = array();
foreach ($bean->filters['vocabulary'] as $vm) {
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'taxonomy_vocabulary');
$query->propertyCondition('machine_name', $vm);
global $language;
if ($language->language != NULL && db_field_exists('taxonomy_vocabulary', 'language')) {
$query->propertyCondition('language', $language->language);
}
$result = $query->execute();
foreach ($result['taxonomy_vocabulary'] as $vocabulary) {
$vids[$vocabulary->vid] = $vocabulary->vid;
}
}
$i = 0;
$content['terms'] = array();
// Parse terms from correct vocabularies, limit list to X results.
foreach ($active_entity['terms'] as $term) {
$term = entity_load_single('taxonomy_term', $term->tid);
if (in_array($term->vid, $vids) && $i < $bean->settings['records_shown']) {
$content['terms'][$term->tid] = entity_view('taxonomy_term', array($term->tid => $term), $bean->settings['term_view_mode']);
$i++;
}
}
cache_set($cache_name, $content, 'cache', time() + 60 * $bean->settings['cache_duration']);
} elseif (isset($active_entity['type']) && $active_entity['type'] == 'bean' && $bean->bid === $active_entity['object']->bid) {
$content['#markup'] = '';
} elseif ($bean->settings['hide_empty'] || !$active_entity['object']) {
return;
} else {
$content['#markup'] = t('No terms.');
}
}
return $content;
}