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


PHP Render\RendererInterface类代码示例

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


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

示例1: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->viewStorage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface');
     $this->executableFactory = $this->getMockBuilder('Drupal\\views\\ViewExecutableFactory')->disableOriginalConstructor()->getMock();
     $this->renderer = $this->getMock('\\Drupal\\Core\\Render\\RendererInterface');
     $this->renderer->expects($this->any())->method('render')->will($this->returnCallback(function (array &$elements) {
         $elements['#attached'] = [];
         return isset($elements['#markup']) ? $elements['#markup'] : '';
     }));
     $this->renderer->expects($this->any())->method('executeInRenderContext')->willReturnCallback(function (RenderContext $context, callable $callable) {
         return $callable();
     });
     $this->currentPath = $this->getMockBuilder('Drupal\\Core\\Path\\CurrentPathStack')->disableOriginalConstructor()->getMock();
     $this->redirectDestination = $this->getMock('\\Drupal\\Core\\Routing\\RedirectDestinationInterface');
     $this->viewAjaxController = new ViewAjaxController($this->viewStorage, $this->executableFactory, $this->renderer, $this->currentPath, $this->redirectDestination);
     $element_info_manager = $this->getMock('\\Drupal\\Core\\Render\\ElementInfoManagerInterface');
     $element_info_manager->expects($this->any())->method('getInfo')->with('markup')->willReturn(['#pre_render' => [[Markup::class, 'ensureMarkupIsSafe']], '#defaults_loaded' => TRUE]);
     $request_stack = new RequestStack();
     $request_stack->push(new Request());
     $args = [$this->getMock('\\Drupal\\Core\\Controller\\ControllerResolverInterface'), $this->getMock('\\Drupal\\Core\\Theme\\ThemeManagerInterface'), $element_info_manager, $this->getMock('\\Drupal\\Core\\Render\\RenderCacheInterface'), $request_stack, ['required_cache_contexts' => ['languages:language_interface', 'theme']]];
     $this->renderer = $this->getMockBuilder('Drupal\\Core\\Render\\Renderer')->setConstructorArgs($args)->setMethods(NULL)->getMock();
     $container = new ContainerBuilder();
     $container->set('renderer', $this->renderer);
     \Drupal::setContainer($container);
 }
开发者ID:scratch,项目名称:gai,代码行数:28,代码来源:ViewAjaxControllerTest.php

示例2: setUp

 protected function setUp()
 {
     $this->viewStorage = $this->getMock('Drupal\\Core\\Entity\\EntityStorageInterface');
     $this->executableFactory = $this->getMockBuilder('Drupal\\views\\ViewExecutableFactory')->disableOriginalConstructor()->getMock();
     $this->renderer = $this->getMock('\\Drupal\\Core\\Render\\RendererInterface');
     $this->renderer->expects($this->any())->method('render')->will($this->returnCallback(function (array &$elements) {
         $elements['#attached'] = [];
         return isset($elements['#markup']) ? $elements['#markup'] : '';
     }));
     $this->currentPath = $this->getMockBuilder('Drupal\\Core\\Path\\CurrentPathStack')->disableOriginalConstructor()->getMock();
     $this->redirectDestination = $this->getMock('\\Drupal\\Core\\Routing\\RedirectDestinationInterface');
     $this->viewAjaxController = new ViewAjaxController($this->viewStorage, $this->executableFactory, $this->renderer, $this->currentPath, $this->redirectDestination);
 }
开发者ID:Nikola-xiii,项目名称:d8intranet,代码行数:13,代码来源:ViewAjaxControllerTest.php

示例3: 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

示例4: process

 /**
  * {@inheritdoc}
  */
 public function process($text, $langcode)
 {
     $response = new FilterProcessResult($text);
     // Use a look ahead to match the capture groups in any order.
     if (preg_match_all('/<p>(?<json>{(?=.*preview_thumbnail\\b)(?=.*settings\\b)(?=.*video_url\\b)(?=.*settings_summary)(.*)})<\\/p>/', $text, $matches)) {
         foreach ($matches['json'] as $delta => $match) {
             // Ensure the JSON string is valid.
             $embed_data = json_decode($match, TRUE);
             if (!is_array($embed_data)) {
                 continue;
             }
             // If the URL can't matched to a provider or the settings are invalid,
             // ignore it.
             $provider = $this->providerManager->loadProviderFromInput($embed_data['video_url']);
             if (!$provider || !$this->validSettings($embed_data['settings'])) {
                 continue;
             }
             $embed_code = $provider->renderEmbedCode($embed_data['settings']['width'], $embed_data['settings']['height'], $embed_data['settings']['autoplay']);
             // Add the container to make the video responsive if it's been
             //configured as such. This usually is attached to field output in the
             // case of a formatter, but a custom container must be used where one is
             // not present.
             if ($embed_data['settings']['responsive']) {
                 $embed_code = ['#type' => 'container', '#attributes' => ['class' => ['video-embed-field-responsive-video']], 'children' => $embed_code];
             }
             // Replace the JSON settings with a video.
             $text = str_replace($matches[0][$delta], $this->renderer->renderRoot($embed_code), $text);
         }
     }
     // Add the required responsive video library and update the response text.
     $response->setProcessedText($text);
     $response->addAttachments(['library' => ['video_embed_field/responsive-video']]);
     return $response;
 }
开发者ID:badelas,项目名称:afroweb,代码行数:37,代码来源:VideoEmbedWysiwyg.php

示例5: displayErrorMessages

 /**
  * Loops through and displays all form errors.
  *
  * @param array $form
  *   An associative array containing the structure of the form.
  * @param \Drupal\Core\Form\FormStateInterface $form_state
  *   The current state of the form.
  */
 protected function displayErrorMessages(array $form, FormStateInterface $form_state)
 {
     $error_links = [];
     $errors = $form_state->getErrors();
     // Loop through all form errors and check if we need to display a link.
     foreach ($errors as $name => $error) {
         $form_element = FormElementHelper::getElementByName($name, $form);
         $title = FormElementHelper::getElementTitle($form_element);
         // Only show links to erroneous elements that are visible.
         $is_visible_element = Element::isVisibleElement($form_element);
         // Only show links for elements that have a title themselves or have
         // children with a title.
         $has_title = !empty($title);
         // Only show links for elements with an ID.
         $has_id = !empty($form_element['#id']);
         // Do not show links to elements with suppressed messages. Most often
         // their parent element is used for inline errors.
         if (!empty($form_element['#error_no_message'])) {
             unset($errors[$name]);
         } elseif ($is_visible_element && $has_title && $has_id) {
             $error_links[] = $this->l($title, Url::fromRoute('<none>', [], ['fragment' => $form_element['#id'], 'external' => TRUE]));
             unset($errors[$name]);
         }
     }
     // Set normal error messages for all remaining errors.
     foreach ($errors as $error) {
         $this->drupalSetMessage($error, 'error');
     }
     if (!empty($error_links)) {
         $render_array = [['#markup' => $this->formatPlural(count($error_links), '1 error has been found: ', '@count errors have been found: ')], ['#theme' => 'item_list', '#items' => $error_links, '#context' => ['list_style' => 'comma-list']]];
         $message = $this->renderer->renderPlain($render_array);
         $this->drupalSetMessage($message, 'error');
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:42,代码来源:FormErrorHandler.php

示例6: 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

示例7: addPage

 /**
  * Displays add links for the available bundles.
  *
  * Redirects to the add form if there's only one bundle available.
  *
  * @param string $entity_type_id
  *   The entity type ID.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The request.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|array
  *   If there's only one available bundle, a redirect response.
  *   Otherwise, a render array with the add links for each bundle.
  */
 public function addPage($entity_type_id, Request $request)
 {
     $entity_type = $this->entityTypeManager()->getDefinition($entity_type_id);
     $bundle_type = $entity_type->getBundleEntityType();
     $bundle_key = $entity_type->getKey('bundle');
     $form_route_name = 'entity.' . $entity_type_id . '.add_form';
     $build = ['#theme' => 'entity_add_list', '#cache' => ['tags' => $entity_type->getListCacheTags()], '#bundle_type' => $bundle_type];
     $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id);
     // Filter out the bundles the user doesn't have access to.
     $access_control_handler = $this->entityTypeManager()->getAccessControlHandler($bundle_type);
     foreach ($bundles as $bundle_name => $bundle_info) {
         $access = $access_control_handler->createAccess($bundle_name, NULL, [], TRUE);
         if (!$access->isAllowed()) {
             unset($bundles[$bundle_name]);
         }
         $this->renderer->addCacheableDependency($build, $access);
     }
     // Redirect if there's only one bundle available.
     if (count($bundles) == 1) {
         $bundle_names = array_keys($bundles);
         $bundle_name = reset($bundle_names);
         return $this->redirect($form_route_name, [$bundle_key => $bundle_name]);
     }
     // Prepare the #bundles array for the template.
     $bundles = $this->loadBundleDescriptions($bundles, $bundle_type);
     foreach ($bundles as $bundle_name => $bundle_info) {
         $build['#bundles'][$bundle_name] = ['label' => $bundle_info['label'], 'description' => $bundle_info['description'], 'add_link' => Link::createFromRoute($bundle_info['label'], $form_route_name, [$bundle_key => $bundle_name])];
     }
     return $build;
 }
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:44,代码来源:EntityCreateController.php

示例8: 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

示例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) {
         $element[$delta] = ['#type' => 'container', '#attributes' => ['data-video-embed-field-modal' => (string) $this->renderer->renderRoot($videos[$delta]), 'class' => ['video-embed-field-launch-modal']], '#attached' => ['library' => ['video_embed_field/colorbox']], 'children' => $thumbnails[$delta]];
     }
     return $element;
 }
开发者ID:robertfoleyjr,项目名称:robertfoleyjr-d8,代码行数:13,代码来源:Colorbox.php

示例10: testUrlBubbleableMetadataBubbling

 /**
  * Tests bubbling of cacheable metadata for URLs.
  *
  * @param bool $collect_bubbleable_metadata
  *   Whether bubbleable metadata should be collected.
  * @param int $invocations
  *   The expected amount of invocations for the ::bubble() method.
  * @param array $options
  *   The URL options.
  *
  * @covers ::bubble
  *
  * @dataProvider providerUrlBubbleableMetadataBubbling
  */
 public function testUrlBubbleableMetadataBubbling($collect_bubbleable_metadata, $invocations, array $options)
 {
     $self = $this;
     $this->renderer->expects($this->exactly($invocations))->method('render')->willReturnCallback(function ($build) use($self) {
         $self->assertTrue(!empty($build['#cache']));
     });
     $url = new Url('test_1', [], $options);
     $url->setUrlGenerator($this->generator);
     $url->toString($collect_bubbleable_metadata);
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:24,代码来源:MetadataBubblingUrlGeneratorTest.php

示例11: execute

 /**
  * {@inheritdoc}
  */
 public function execute($entity = NULL)
 {
     if (empty($this->configuration['node'])) {
         $this->configuration['node'] = $entity;
     }
     $message = $this->token->replace($this->configuration['message'], $this->configuration);
     $build = ['#markup' => $message];
     // @todo Fix in https://www.drupal.org/node/2577827
     drupal_set_message($this->renderer->renderPlain($build));
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:13,代码来源:MessageAction.php

示例12: 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

示例13: 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

示例14: execute

 /**
  * {@inheritdoc}
  */
 public function execute($comment = NULL)
 {
     $build = $this->viewBuilder->view($comment);
     $text = $this->renderer->renderPlain($build);
     foreach ($this->configuration['keywords'] as $keyword) {
         if (strpos($text, $keyword) !== FALSE) {
             $comment->setPublished(FALSE);
             $comment->save();
             break;
         }
     }
 }
开发者ID:sarahwillem,项目名称:OD8,代码行数:15,代码来源:UnpublishByKeywordComment.php

示例15: 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


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