当前位置: 首页>>代码示例>>PHP>>正文


PHP RendererInterface::render方法代码示例

本文整理汇总了PHP中Drupal\Core\Render\RendererInterface::render方法的典型用法代码示例。如果您正苦于以下问题:PHP RendererInterface::render方法的具体用法?PHP RendererInterface::render怎么用?PHP RendererInterface::render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Render\RendererInterface的用法示例。


在下文中一共展示了RendererInterface::render方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getDescription

 /**
  * {@inheritdoc}
  */
 public function getDescription()
 {
     $locked = $this->tempStore->getMetadata($this->entity->id());
     $account = $this->entityTypeManager->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' => $this->renderer->render($username)));
 }
开发者ID:curveagency,项目名称:intranet,代码行数:10,代码来源:IndexBreakLockForm.php

示例2: getDescription

 /**
  * {@inheritdoc}
  */
 public function getDescription()
 {
     $locked = $this->rulesUiHandler->getLockMetaData();
     $account = $this->entityTypeManager->getStorage('user')->load($locked->owner);
     $username = ['#theme' => 'username', '#account' => $account];
     return $this->t('By breaking this lock, any unsaved changes made by @user will be lost.', ['@user' => $this->renderer->render($username)]);
 }
开发者ID:Progressable,项目名称:openway8,代码行数:10,代码来源:BreakLockForm.php

示例3: generate

 /**
  * {@inheritdoc}
  *
  * For anonymous users, the "active" class will be calculated on the server,
  * because most sites serve each anonymous user the same cached page anyway.
  * For authenticated users, the "active" class will be calculated on the
  * client (through JavaScript), only data- attributes are added to links to
  * prevent breaking the render cache. The JavaScript is added in
  * system_page_attachments().
  *
  * @see system_page_attachments()
  */
 public function generate($text, Url $url, $collect_cacheability_metadata = FALSE)
 {
     // Performance: avoid Url::toString() needing to retrieve the URL generator
     // service from the container.
     $url->setUrlGenerator($this->urlGenerator);
     // Start building a structured representation of our link to be altered later.
     $variables = array('text' => is_array($text) ? $this->renderer->render($text) : $text, 'url' => $url, 'options' => $url->getOptions());
     // Merge in default options.
     $variables['options'] += array('attributes' => array(), 'query' => array(), 'language' => NULL, 'set_active_class' => FALSE, 'absolute' => FALSE);
     // Add a hreflang attribute if we know the language of this link's url and
     // hreflang has not already been set.
     if (!empty($variables['options']['language']) && !isset($variables['options']['attributes']['hreflang'])) {
         $variables['options']['attributes']['hreflang'] = $variables['options']['language']->getId();
     }
     // Set the "active" class if the 'set_active_class' option is not empty.
     if (!empty($variables['options']['set_active_class']) && !$url->isExternal()) {
         // Add a "data-drupal-link-query" attribute to let the
         // drupal.active-link library know the query in a standardized manner.
         if (!empty($variables['options']['query'])) {
             $query = $variables['options']['query'];
             ksort($query);
             $variables['options']['attributes']['data-drupal-link-query'] = Json::encode($query);
         }
         // Add a "data-drupal-link-system-path" attribute to let the
         // drupal.active-link library know the path in a standardized manner.
         if ($url->isRouted() && !isset($variables['options']['attributes']['data-drupal-link-system-path'])) {
             // @todo System path is deprecated - use the route name and parameters.
             $system_path = $url->getInternalPath();
             // Special case for the front page.
             $variables['options']['attributes']['data-drupal-link-system-path'] = $system_path == '' ? '<front>' : $system_path;
         }
     }
     // Remove all HTML and PHP tags from a tooltip, calling expensive strip_tags()
     // only when a quick strpos() gives suspicion tags are present.
     if (isset($variables['options']['attributes']['title']) && strpos($variables['options']['attributes']['title'], '<') !== FALSE) {
         $variables['options']['attributes']['title'] = strip_tags($variables['options']['attributes']['title']);
     }
     // Allow other modules to modify the structure of the link.
     $this->moduleHandler->alter('link', $variables);
     // Move attributes out of options since generateFromRoute() doesn't need
     // them. Include a placeholder for the href.
     $attributes = array('href' => '') + $variables['options']['attributes'];
     unset($variables['options']['attributes']);
     $url->setOptions($variables['options']);
     if (!$collect_cacheability_metadata) {
         $url_string = $url->toString($collect_cacheability_metadata);
     } else {
         $generated_url = $url->toString($collect_cacheability_metadata);
         $url_string = $generated_url->getGeneratedUrl();
         $generated_link = GeneratedLink::createFromObject($generated_url);
     }
     // The result of the URL generator is a plain-text URL to use as the href
     // attribute, and it is escaped by \Drupal\Core\Template\Attribute.
     $attributes['href'] = $url_string;
     $result = SafeMarkup::format('<a@attributes>@text</a>', array('@attributes' => new Attribute($attributes), '@text' => $variables['text']));
     return $collect_cacheability_metadata ? $generated_link->setGeneratedLink($result) : $result;
 }
开发者ID:RealLukeMartin,项目名称:drupal8tester,代码行数:69,代码来源:LinkGenerator.php

示例4: toolbarAction

 /**
  * Generates the toolbar.
  *
  * @param Profile $profile
  *
  * @return array
  */
 public function toolbarAction(Profile $profile)
 {
     $this->profiler->disable();
     $templates = $this->templateManager->getTemplates($profile);
     $rendered = '';
     foreach ($templates as $name => $template) {
         $rendered .= $template->renderBlock('toolbar', ['collector' => $profile->getcollector($name), 'token' => $profile->getToken(), 'name' => $name]);
     }
     $toolbar = ['#theme' => 'webprofiler_toolbar', '#toolbar' => $rendered, '#token' => $profile->getToken()];
     return new Response($this->renderer->render($toolbar));
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:18,代码来源:ToolbarController.php

示例5: buildListingLevel

 /**
  * Helper function for self::listing() to build table rows.
  *
  * @param array[] $hierarchy
  *   Keys are plugin IDs, and values are arrays of the same structure as this
  *   parameter. The depth is unlimited.
  * @param integer $depth
  *   The depth of $hierarchy's top-level items as seen from the original
  *   hierarchy's root (this function is recursive), starting with 0.
  *
  * @return array
  *   A render array.
  */
 protected function buildListingLevel(array $hierarchy, $depth)
 {
     $rows = [];
     foreach ($hierarchy as $plugin_id => $children) {
         $definition = $this->paymentStatusManager->getDefinition($plugin_id);
         $operations_provider = $this->paymentStatusManager->getOperationsProvider($plugin_id);
         $indentation = ['#theme' => 'indentation', '#size' => $depth];
         $rows[$plugin_id] = ['label' => ['#markup' => $this->renderer->render($indentation) . $definition['label']], 'description' => ['#markup' => $definition['description']], 'operations' => ['#type' => 'operations', '#links' => $operations_provider ? $operations_provider->getOperations($plugin_id) : []]];
         $rows = array_merge($rows, $this->buildListingLevel($children, $depth + 1));
     }
     return $rows;
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:25,代码来源:ListPaymentStatuses.php

示例6: bubble

 /**
  * Bubbles the bubbleable metadata to the current render context.
  *
  * @param \Drupal\Core\GeneratedUrl $generated_url
  *   The generated URL whose bubbleable metadata to bubble.
  * @param array $options
  *   (optional) The URL options. Defaults to none.
  */
 protected function bubble(GeneratedUrl $generated_url, array $options = [])
 {
     // Bubbling metadata makes sense only if the code is executed inside a
     // render context. All code running outside controllers has no render
     // context by default, so URLs used there are not supposed to affect the
     // response cacheability.
     if ($this->renderer->hasRenderContext()) {
         $build = [];
         $generated_url->applyTo($build);
         $this->renderer->render($build);
     }
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:20,代码来源:MetadataBubblingUrlGenerator.php

示例7: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $block_instance = $this->getBlockInstance($form_state);
     // Submit the block configuration form.
     $block_form_state = (new FormState())->setValues($form_state->getValue('settings'));
     $block_instance->submitConfigurationForm($form, $block_form_state);
     // Update the original form values.
     $form_state->setValue('settings', $block_form_state->getValues());
     // If a temporary configuration for this variant exists, use it.
     $temp_store_key = $this->panelsDisplay->id();
     if ($variant_config = $this->tempStore->get($temp_store_key)) {
         $this->panelsDisplay->setConfiguration($variant_config);
     }
     // Set the block region appropriately.
     $block_config = $block_instance->getConfiguration();
     $block_config['region'] = $form_state->getValue(array('settings', 'region'));
     // Determine if we need to update or add this block.
     if ($uuid = $form_state->getValue('uuid')) {
         $this->panelsDisplay->updateBlock($uuid, $block_config);
     } else {
         $uuid = $this->panelsDisplay->addBlock($block_config);
     }
     // Set the tempstore value.
     $this->tempStore->set($this->panelsDisplay->id(), $this->panelsDisplay->getConfiguration());
     // Assemble data required for our App.
     $build = $this->buildBlockInstance($block_instance);
     $form['build'] = $build;
     // Add our data attribute for the Backbone app.
     $build['#attributes']['data-block-id'] = $uuid;
     $block_model = ['uuid' => $uuid, 'label' => $block_instance->label(), 'id' => $block_instance->getPluginId(), 'region' => $block_config['region'], 'html' => $this->renderer->render($build)];
     // Add Block metadata and HTML as a drupalSetting.
     $form['#attached']['drupalSettings']['panels_ipe']['updated_block'] = $block_model;
     return $form;
 }
开发者ID:neeravbm,项目名称:unify-d8,代码行数:37,代码来源:PanelsIPEBlockPluginForm.php

示例8: buildTitle

 /**
  * Pre-render callback to build the page title.
  *
  * @param array $page
  *   A page render array.
  *
  * @return array
  *   The changed page render array.
  */
 public function buildTitle(array $page)
 {
     $entity_type = $page['#entity_type'];
     $entity = $page['#' . $entity_type];
     // If the entity's label is rendered using a field formatter, set the
     // rendered title field formatter as the page title instead of the default
     // plain text title. This allows attributes set on the field to propagate
     // correctly (e.g. RDFa, in-place editing).
     if ($entity instanceof FieldableEntityInterface) {
         $label_field = $entity->getEntityType()->getKey('label');
         if (isset($page[$label_field])) {
             $page['#title'] = $this->renderer->render($page[$label_field]);
         }
     }
     return $page;
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:25,代码来源:EntityViewController.php

示例9: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $element = [];
     $thumbnails = $this->thumbnailFormatter->viewElements($items, $langcode);
     $videos = $this->videoFormatter->viewElements($items, $langcode);
     foreach ($items as $delta => $item) {
         // Support responsive videos within the colorbox modal.
         if ($this->getSetting('responsive')) {
             $videos[$delta]['#attributes']['class'][] = 'video-embed-field-responsive-modal';
             $videos[$delta]['#attributes']['style'] = sprintf('width:%dpx;', $this->getSetting('modal_max_width'));
         }
         $element[$delta] = ['#type' => 'container', '#attributes' => ['data-video-embed-field-modal' => (string) $this->renderer->render($videos[$delta]), 'class' => ['video-embed-field-launch-modal']], '#attached' => ['library' => ['video_embed_field/colorbox', 'video_embed_field/responsive-video']], '#cache' => ['contexts' => ['user.permissions']], 'children' => $thumbnails[$delta]];
     }
     $this->colorboxAttachment->attach($element);
     return $element;
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:19,代码来源:Colorbox.php

示例10: getRevisionDescription

 /**
  * {@inheritdoc}
  */
 protected function getRevisionDescription(ContentEntityInterface $revision, $is_default = FALSE)
 {
     /** @var \Drupal\Core\Entity\ContentEntityInterface|\Drupal\user\EntityOwnerInterface|\Drupal\Core\Entity\RevisionLogInterface $revision */
     if ($revision instanceof RevisionLogInterface) {
         // Use revision link to link to revisions that are not active.
         $date = $this->dateFormatter->format($revision->getRevisionCreationTime(), 'short');
         $link = $revision->toLink($date, 'revision');
         // @todo: Simplify this when https://www.drupal.org/node/2334319 lands.
         $username = ['#theme' => 'username', '#account' => $revision->getRevisionUser()];
         $username = $this->renderer->render($username);
     } else {
         $link = $revision->toLink($revision->label(), 'revision');
         $username = '';
     }
     $markup = '';
     if ($revision instanceof RevisionLogInterface) {
         $markup = $revision->getRevisionLogMessage();
     }
     if ($username) {
         $template = '{% trans %}{{ date }} by {{ username }}{% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}';
     } else {
         $template = '{% trans %} {{ date }} {% endtrans %}{% if message %}<p class="revision-log">{{ message }}</p>{% endif %}';
     }
     $column = ['data' => ['#type' => 'inline_template', '#template' => $template, '#context' => ['date' => $link->toString(), 'username' => $username, 'message' => ['#markup' => $markup, '#allowed_tags' => Xss::getHtmlTagList()]]]];
     return $column;
 }
开发者ID:CIGIHub,项目名称:bsia-drupal8,代码行数:29,代码来源:RevisionOverviewController.php

示例11: cacheSet

 /**
  * Save data to the cache.
  *
  * A plugin should override this to provide specialized caching behavior.
  */
 public function cacheSet($type)
 {
     switch ($type) {
         case 'query':
             // Not supported currently, but this is certainly where we'd put it.
             break;
         case 'results':
             $data = array('result' => $this->prepareViewResult($this->view->result), 'total_rows' => isset($this->view->total_rows) ? $this->view->total_rows : 0, 'current_page' => $this->view->getCurrentPage());
             \Drupal::cache($this->resultsBin)->set($this->generateResultsKey(), $data, $this->cacheSetExpire($type), $this->getCacheTags());
             break;
         case 'output':
             // Make a copy of the output so it is not modified. If we render the
             // display output directly an empty string will be returned when the
             // view is actually rendered. If we try to set '#printed' to FALSE there
             // are problems with asset bubbling.
             $output = $this->view->display_handler->output;
             $this->renderer->render($output);
             // Also assign the cacheable render array back to the display handler so
             // that is used to render the view for this request and rendering does
             // not happen twice.
             $this->storage = $this->view->display_handler->output = $this->renderer->getCacheableRenderArray($output);
             \Drupal::cache($this->outputBin)->set($this->generateOutputKey(), $this->storage, $this->cacheSetExpire($type), Cache::mergeTags($this->storage['#cache']['tags'], ['rendered']));
             break;
     }
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:30,代码来源:CachePluginBase.php

示例12: getLayout

 /**
  * Gets a given layout with empty regions and relevant metadata.
  *
  * @param \Drupal\page_manager\PageVariantInterface $page_variant
  *   The page variant entity.
  * @param string $layout_id
  *   The machine name of the requested layout.
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  */
 public function getLayout(PageVariantInterface $page_variant, $layout_id)
 {
     /** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $variant_plugin */
     $variant_plugin = $page_variant->getVariantPlugin();
     // Build the requested layout.
     $configuration = $variant_plugin->getConfiguration();
     $configuration['layout'] = $layout_id;
     $variant_plugin->setConfiguration($configuration);
     // Inherit our PageVariant's contexts before rendering.
     $variant_plugin->setContexts($page_variant->getContexts());
     $regions = $variant_plugin->getRegionNames();
     $region_data = [];
     $region_content = [];
     // Compile region content and metadata.
     foreach ($regions as $id => $label) {
         // Wrap the region with a class/data attribute that our app can use.
         $region_name = Html::getClass("block-region-{$id}");
         $region_content[$id] = ['#prefix' => '<div class="' . $region_name . '" data-region-name="' . $id . '">', '#suffix' => '</div>'];
         // Format region metadata.
         $region_data[] = ['name' => $id, 'label' => $label];
     }
     $build = $variant_plugin->getLayout()->build($region_content);
     // Get the current layout.
     $current_layout = $variant_plugin->getLayout()->getPluginId();
     // Get a list of all available layouts.
     $layouts = $this->layoutPluginManager->getLayoutOptions();
     $data = ['id' => $layout_id, 'label' => $layouts[$layout_id], 'current' => $current_layout == $layout_id, 'html' => $this->renderer->render($build), 'regions' => $region_data];
     // Update temp store.
     $this->savePageVariant($page_variant);
     // Return a structured JSON response for our Backbone App.
     return new JsonResponse($data);
 }
开发者ID:jeroenos,项目名称:jeroenos_d8.mypressonline.com,代码行数:42,代码来源:PanelsIPEPageController.php

示例13: renderVar

 /**
  * Wrapper around render() for twig printed output.
  *
  * If an object is passed which does not implement __toString(),
  * RenderableInterface or toString() then an exception is thrown;
  * Other objects are casted to string. However in the case that the
  * object is an instance of a Twig_Markup object it is returned directly
  * to support auto escaping.
  *
  * If an array is passed it is rendered via render() and scalar values are
  * returned directly.
  *
  * @param mixed $arg
  *   String, Object or Render Array.
  *
  * @throws \Exception
  *   When $arg is passed as an object which does not implement __toString(),
  *   RenderableInterface or toString().
  *
  * @return mixed
  *   The rendered output or an Twig_Markup object.
  *
  * @see render
  * @see TwigNodeVisitor
  */
 public function renderVar($arg)
 {
     // Check for a numeric zero int or float.
     if ($arg === 0 || $arg === 0.0) {
         return 0;
     }
     // Return early for NULL and empty arrays.
     if ($arg == NULL) {
         return NULL;
     }
     // Optimize for scalars as it is likely they come from the escape filter.
     if (is_scalar($arg)) {
         return $arg;
     }
     if (is_object($arg)) {
         $this->bubbleArgMetadata($arg);
         if ($arg instanceof RenderableInterface) {
             $arg = $arg->toRenderable();
         } elseif (method_exists($arg, '__toString')) {
             return (string) $arg;
         } elseif (method_exists($arg, 'toString')) {
             return $arg->toString();
         } else {
             throw new \Exception('Object of type ' . get_class($arg) . ' cannot be printed.');
         }
     }
     // This is a render array, with special simple cases already handled.
     // Early return if this element was pre-rendered (no need to re-render).
     if (isset($arg['#printed']) && $arg['#printed'] == TRUE && isset($arg['#markup']) && strlen($arg['#markup']) > 0) {
         return $arg['#markup'];
     }
     $arg['#printed'] = FALSE;
     return $this->renderer->render($arg);
 }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:59,代码来源:TwigExtension.php

示例14: prepare

 /**
  * Prepares the HTML body: wraps the main content in #type 'page'.
  *
  * @param array $main_content
  *   The render array representing the main content.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request object, for context.
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match, for context.
  *
  * @return array
  *   An array with two values:
  *   0. A #type 'page' render array.
  *   1. The page title.
  *
  * @throws \LogicException
  *   If the selected display variant does not implement PageVariantInterface.
  */
 protected function prepare(array $main_content, Request $request, RouteMatchInterface $route_match)
 {
     // If the _controller result already is #type => page,
     // we have no work to do: The "main content" already is an entire "page"
     // (see html.html.twig).
     if (isset($main_content['#type']) && $main_content['#type'] === 'page') {
         $page = $main_content;
     } else {
         // Select the page display variant to be used to render this main content,
         // default to the built-in "simple page".
         $event = new PageDisplayVariantSelectionEvent('simple_page', $route_match);
         $this->eventDispatcher->dispatch(RenderEvents::SELECT_PAGE_DISPLAY_VARIANT, $event);
         $variant_id = $event->getPluginId();
         // We must render the main content now already, because it might provide a
         // title. We set its $is_root_call parameter to FALSE, to ensure
         // placeholders are not yet replaced. This is essentially "pre-rendering"
         // the main content, the "full rendering" will happen in
         // ::renderResponse().
         // @todo Remove this once https://www.drupal.org/node/2359901 lands.
         if (!empty($main_content)) {
             $this->renderer->executeInRenderContext(new RenderContext(), function () use(&$main_content) {
                 if (isset($main_content['#cache']['keys'])) {
                     // Retain #title, otherwise, dynamically generated titles would be
                     // missing for controllers whose entire returned render array is
                     // render cached.
                     $main_content['#cache_properties'][] = '#title';
                 }
                 return $this->renderer->render($main_content, FALSE);
             });
             $main_content = $this->renderCache->getCacheableRenderArray($main_content) + ['#title' => isset($main_content['#title']) ? $main_content['#title'] : NULL];
         }
         // Instantiate the page display, and give it the main content.
         $page_display = $this->displayVariantManager->createInstance($variant_id);
         if (!$page_display instanceof PageVariantInterface) {
             throw new \LogicException('Cannot render the main content for this page because the provided display variant does not implement PageVariantInterface.');
         }
         $page_display->setMainContent($main_content)->setConfiguration($event->getPluginConfiguration());
         // Generate a #type => page render array using the page display variant,
         // the page display will build the content for the various page regions.
         $page = array('#type' => 'page');
         $page += $page_display->build();
     }
     // $page is now fully built. Find all non-empty page regions, and add a
     // theme wrapper function that allows them to be consistently themed.
     $regions = \Drupal::theme()->getActiveTheme()->getRegions();
     foreach ($regions as $region) {
         if (!empty($page[$region])) {
             $page[$region]['#theme_wrappers'][] = 'region';
             $page[$region]['#region'] = $region;
         }
     }
     // Allow hooks to add attachments to $page['#attached'].
     $this->invokePageAttachmentHooks($page);
     // Determine the title: use the title provided by the main content if any,
     // otherwise get it from the routing information.
     $title = isset($main_content['#title']) ? $main_content['#title'] : $this->titleResolver->getTitle($request, $route_match->getRouteObject());
     return [$page, $title];
 }
开发者ID:ravindrasingh22,项目名称:Drupal-8-rc,代码行数:76,代码来源:HtmlRenderer.php

示例15: ajaxAddMoreSubmit

 /**
  * Implements form AJAX callback.
  */
 public function ajaxAddMoreSubmit(array &$form, FormStateInterface $form_state)
 {
     $triggering_element = $form_state->getTriggeringElement();
     $parents = array_slice($triggering_element['#array_parents'], 0, -2);
     $root_element = NestedArray::getValue($form, $parents);
     $response = new AjaxResponse();
     $response->addCommand(new ReplaceCommand('#' . $root_element['#id'], $this->renderer->render($root_element)));
     return $response;
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:12,代码来源:PaymentLineItemsInput.php


注:本文中的Drupal\Core\Render\RendererInterface::render方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。