本文整理汇总了PHP中entity_view函数的典型用法代码示例。如果您正苦于以下问题:PHP entity_view函数的具体用法?PHP entity_view怎么用?PHP entity_view使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了entity_view函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:rafavergara,项目名称:ddv8,代码行数:31,代码来源:FilterMailchimpCampaign.php
示例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;
}
开发者ID:jkyto,项目名称:agolf,代码行数:40,代码来源:DsDevelController.php
示例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.');
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:28,代码来源:UserBlocksTest.php
示例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');
}
开发者ID:pioneerroad,项目名称:gitp-theme,代码行数:7,代码来源:template-preprocess.php
示例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;
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:30,代码来源:EntityReferenceEntityFormatter.php
示例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);
}
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:37,代码来源:BlockViewBuilderTest.php
示例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;
}
开发者ID:antoniodltm,项目名称:pinolguitars,代码行数:14,代码来源:commerce_search.api.php
示例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;
}
开发者ID:318io,项目名称:318-io,代码行数:28,代码来源:ExpoController.php
示例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;
}
开发者ID:318io,项目名称:318-io,代码行数:11,代码来源:FrontExpoBlock.php
示例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]));
}
开发者ID:bangpound,项目名称:drupal-bundle,代码行数:15,代码来源:EntityController.php
示例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;
}
开发者ID:edwardchan,项目名称:d8-drupalvm,代码行数:13,代码来源:CommentUser.php
示例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;
}
开发者ID:ec-europa,项目名称:platform-dev,代码行数:13,代码来源:NodeViewModeType.php
示例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();
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:14,代码来源:Entity.php
示例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;
}
开发者ID:neeravbm,项目名称:unify-d8,代码行数:26,代码来源:DsExtrasController.php
示例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;
}
开发者ID:stevebresnick,项目名称:iomedia_stp_d7_core,代码行数:50,代码来源:TaxListingBean.class.php
示例16: assertFormatterRdfa
/**
* Helper function to test the formatter's RDFa.
*
* @param array $formatter
* An associative array describing the formatter to test and its settings
* containing:
* - type: The machine name of the field formatter to test.
* - settings: The settings of the field formatter to test.
* @param string $property
* The property that should be found.
* @param array $expected_rdf_value
* An associative array describing the expected value of the property
* containing:
* - value: The actual value of the string or URI.
* - type: The type of RDF value, e.g. 'literal' for a string, or 'uri'.
* Defaults to 'literal'.
* - datatype: (optional) The datatype of the value (e.g. xsd:dateTime).
*/
protected function assertFormatterRdfa($formatter, $property, $expected_rdf_value)
{
$expected_rdf_value += array('type' => 'literal');
// The field formatter will be rendered inside the entity. Set the field
// formatter in the entity display options before rendering the entity.
entity_get_display('entity_test', 'entity_test', 'default')->setComponent($this->fieldName, $formatter)->save();
$build = entity_view($this->entity, 'default');
$output = drupal_render($build);
$graph = new \EasyRdf_Graph($this->uri, $output, 'rdfa');
// If verbose debugging is turned on, display the HTML and parsed RDF
// in the results.
if ($this->debug) {
debug($output);
debug($graph->toRdfPhp());
}
$this->assertTrue($graph->hasProperty($this->uri, $property, $expected_rdf_value), "Formatter {$formatter['type']} exposes data correctly for {$this->fieldType} fields.");
}
开发者ID:anatalsceo,项目名称:en-classe,代码行数:35,代码来源:FieldRdfaTestBase.php
示例17: entityMarkup
/**
* Lists all instances of fields on any views.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* A RouteMatch object.
*
* @return array
* The Views fields report page.
*/
public function entityMarkup(RouteMatchInterface $route_match)
{
$parameter_name = $route_match->getRouteObject()->getOption('_devel_entity_type_id');
$entity = $route_match->getParameter($parameter_name);
$entity_type_id = $entity->getEntityTypeId();
$key = \Drupal::request()->get('key', 'default');
$builded_entity = entity_view($entity, $key);
$markup = \Drupal::service('renderer')->render($builded_entity);
$links = array();
$active_view_modes = \Drupal::service('entity_display.repository')->getViewModeOptionsByBundle($entity_type_id, $entity->bundle());
foreach ($active_view_modes as $id => $label) {
$links[] = array('title' => $label, 'url' => Url::fromRoute("entity.{$entity_type_id}.devel_markup", array($entity_type_id => $entity->id(), 'key' => $id)));
}
$build['links'] = array('#theme' => 'links', '#links' => $links, '#prefix' => '<hr/><div>', '#suffix' => '</div><hr />');
$build['markup'] = ['#markup' => '<code><pre>' . Html::escape($markup) . '</pre></code>', '#cache' => array('max-age' => 0), '#allowed_tags' => ['code', 'pre']];
return $build;
}
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:26,代码来源:DsDevelController.php
示例18: testAccess
/**
* Assert unaccessible items don't change the data of the fields.
*/
public function testAccess()
{
$field_name = $this->fieldName;
$referencing_entity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
$referencing_entity->save();
$referencing_entity->{$field_name}->entity = $this->referencedEntity;
// Assert user doesn't have access to the entity.
$this->assertFalse($this->referencedEntity->access('view'), 'Current user does not have access to view the referenced entity.');
$formatter_manager = $this->container->get('plugin.manager.field.formatter');
// Get all the existing formatters.
foreach ($formatter_manager->getOptions('entity_reference') as $formatter => $name) {
// Set formatter type for the 'full' view mode.
entity_get_display($this->entityType, $this->bundle, 'default')->setComponent($field_name, array('type' => $formatter))->save();
// Invoke entity view.
entity_view($referencing_entity, 'default');
// Verify the un-accessible item still exists.
$this->assertEqual($referencing_entity->{$field_name}->target_id, $this->referencedEntity->id(), format_string('The un-accessible item still exists after @name formatter was executed.', array('@name' => $name)));
}
}
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:22,代码来源:EntityReferenceFormatterTest.php
示例19: build
/**
* {@inheritdoc}
*/
public function build()
{
$config = $this->getConfiguration();
$nr_items = isset($config['slideshow_items']) ? $config['slideshow_items'] : 3;
// $order = isset($config['slideshow_order']) ? $config['slideshow_order'] : 'created';
// Fetches the slideshow nodes.
$query = \Drupal::entityQuery('node')->condition('status', 1)->condition('type', 'object')->range(0, $nr_items);
$nids = $query->execute();
$items = array();
foreach ($nids as $nid) {
$node = entity_load('node', $nid);
$node_view = entity_view($node, 'hero_teaser');
$items[] = array('#markup' => drupal_render($node_view), '#wrapper_attributes' => array('class' => array('slide')));
}
$build['show'] = array('#theme' => 'item_list', '#items' => $items, '#attributes' => array('class' => array('slideshow', 'rslides')));
$build['#attributes']['class'][] = 'slideshow-block';
$build['#attached']['library'][] = 'dd8_tools/slideshow';
$build['#attached']['library'][] = 'dd8_tools/responsiveslides';
// $build['asfasf']['#markup'] = 'efkjqekjfkjah aekjkjwevkj HSHAJHDJAH';
return $build;
}
开发者ID:batigolix,项目名称:doesdesign8,代码行数:24,代码来源:Dd_toolsSlideshow.php
示例20: casabienestar_preprocess_search_api_page_results
function casabienestar_preprocess_search_api_page_results(array &$variables)
{
$results = $variables['results'];
if (!empty($variables['results']['results'])) {
$variables['items'] = $variables['index']->loadItems(array_keys($variables['results']['results']));
}
$variables['result_count'] = $results['result count'];
$variables['sec'] = 0;
if (isset($results['performance']['complete'])) {
$variables['sec'] = round($results['performance']['complete'], 3);
}
$variables['search_performance'] = array('#theme' => 'search_api_page_search_performance', '#markup' => format_plural($results['result count'], 'The search found 1 result in @sec seconds.', 'The search found @count results in @sec seconds.', array('@sec' => $variables['sec'])), '#prefix' => '<p class="search-performance">', '#suffix' => '</p>');
// Make the help text depend on the parse mode used.
switch ($variables['page']->options['mode']) {
case 'direct':
if ($variables['index']->server()->class == 'search_api_solr') {
$variables['no_results_help'] = t('<ul>
<li>Check if your spelling is correct.</li>
<li>Remove quotes around phrases to search for each word individually. <em>bike shed</em> will often show more results than <em>"bike shed"</em>.</li>
<li>Consider loosening your query with <em>OR</em>. <em>bike OR shed</em> will often show more results than <em>bike shed</em>.</li>
</ul>');
} else {
$variables['no_results_help'] = t('<ul>
<li>Check if your spelling is correct.</li>
<li>Use fewer keywords to increase the number of results.</li>
</ul>');
}
break;
case 'single':
$variables['no_results_help'] = t('<ul>
<li>Check if your spelling is correct.</li>
<li>Use fewer keywords to increase the number of results.</li>
</ul>');
break;
case 'terms':
$variables['no_results_help'] = t('<ul>
<li>Check if your spelling is correct.</li>
<li>Remove quotes around phrases to search for each word individually. <em>bike shed</em> will often show more results than <em>"bike shed"</em>.</li>
<li>Use fewer keywords to increase the number of results.</li>
</ul>');
break;
}
// Prepare CSS classes.
$classes_array = array('search-api-page', 'search-api-page-' . drupal_clean_css_identifier($variables['page']->machine_name), 'view-mode-' . drupal_clean_css_identifier($variables['view_mode']));
$variables['classes'] = implode(' ', $classes_array);
// Distinguish between the native search_api_page_result "view mode" and
// proper entity view modes (e.g., Teaser, Full content, RSS and so forth).
$variables['search_results'] = array();
if ($variables['view_mode'] != 'search_api_page_result') {
// Check if we have any entities to show and, if yes, show them.
if (!empty($variables['items'])) {
$variables['search_results'] = entity_view($variables['index']->getEntityType(), $variables['items'], $variables['view_mode']);
}
} else {
foreach ($results['results'] as $item) {
if (!empty($variables['items'][$item['id']])) {
$variables['search_results'][] = array('#theme' => 'search_api_page_result', '#index' => $variables['index'], '#result' => $item, '#item' => $variables['items'][$item['id']]);
}
}
}
// Load CSS.
$base_path = drupal_get_path('module', 'search_api_page') . '/';
drupal_add_css($base_path . 'search_api_page.css');
}
开发者ID:brm-tangarifec,项目名称:casabienestar,代码行数:64,代码来源:template_cb.php
注:本文中的entity_view函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论