renderPlain example

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->messenger->addError($message);
    }
  }

}

    $view->save();

    /** @var \Drupal\Core\Render\RendererInterface $renderer */
    $renderer = \Drupal::service('renderer');
    /** @var \Drupal\Core\Session\AccountSwitcherInterface $account_switcher */
    $account_switcher = \Drupal::service('account_switcher');

    // First access as user with access.     $build = DisplayPluginBase::buildBasicRenderable('test_access_role', 'default');
    $account_switcher->switchTo($this->normalUser);
    $result = $renderer->renderPlain($build);
    $this->assertContains('user.roles', $build['#cache']['contexts']);
    $this->assertEquals(['config:views.view.test_access_role']$build['#cache']['tags']);
    $this->assertEquals(Cache::PERMANENT, $build['#cache']['max-age']);
    $this->assertNotSame('', $result);

    // Then without access.     $build = DisplayPluginBase::buildBasicRenderable('test_access_role', 'default');
    $account_switcher->switchTo($this->webUser);
    $result = $renderer->renderPlain($build);
    // @todo Fix this in https://www.drupal.org/node/2551037,     // DisplayPluginBase::applyDisplayCacheabilityMetadata() is not invoked when
if (isset($element[$key]['#dropbutton'])) {
        $dropbutton = $element[$key]['#dropbutton'];
        // If there is no dropbutton for this button group yet, create one.         if (!isset($dropbuttons[$dropbutton])) {
          $dropbuttons[$dropbutton] = [
            '#type' => 'dropbutton',
          ];
        }
        // Add this button to the corresponding dropbutton.         // @todo Change #type 'dropbutton' to be based on item-list.html.twig         // instead of links.html.twig to avoid this preemptive rendering.         $button = \Drupal::service('renderer')->renderPlain($element[$key]);
        $dropbuttons[$dropbutton]['#links'][$key] = [
          'title' => $button,
        ];
        // Merge metadata like drupalSettings.         BubbleableMetadata::createFromRenderArray($dropbuttons[$dropbutton])
          ->merge(BubbleableMetadata::createFromRenderArray($element[$key]))
          ->applyTo($dropbuttons[$dropbutton]);
      }
    }
    // @todo For now, all dropbuttons appear first. Consider to invent a more     // fancy sorting/injection algorithm here.
foreach ($tips as $index => $tip) {
        $classes = [
          'tip-module-' . Html::getClass($tourEntity->getModule()),
          'tip-type-' . Html::getClass($tip->getPluginId()),
          'tip-' . Html::getClass($tip->id()),
        ];

        $selector = $tip->getSelector();
        $location = $tip->getLocation();

        $body_render_array = $tip->getBody();
        $body = (string) \Drupal::service('renderer')->renderPlain($body_render_array);
        $output = [
          'body' => $body,
          'title' => $tip->getLabel(),
        ];

        $selector = $tip->getSelector();

        if ($output) {
          $items[] = [
            'id' => $tip->id(),
            'selector' => $selector,
            
// Verify that the #description element is visually-hidden.     $this->assertSession()->elementExists('xpath', '//input[@id="' . $field_id . '" and @aria-describedby="' . $description_id . '"]/following-sibling::div[contains(@class, "visually-hidden")]');
  }

  /** * Tests forms in theme-less environments. */
  public function testFormsInThemeLessEnvironments() {
    $form = $this->getFormWithLimitedProperties();
    $render_service = $this->container->get('renderer');
    // This should not throw any notices.     $render_service->renderPlain($form);
  }

  /** * Return a form with element with not all properties defined. */
  protected function getFormWithLimitedProperties() {
    $form = [];

    $form['fieldset'] = [
      '#type' => 'fieldset',
      '#title' => 'Fieldset',
    ];
case 'module-disabled':
          case 'theme-disabled':
            $projects['disabled'][$name] = $entry;
            break;
        }
      }
    }

    if ($fetch_failed) {
      $message = ['#theme' => 'update_fetch_error_message'];
      $this->messenger()->addError(\Drupal::service('renderer')->renderPlain($message));
    }

    if (empty($projects)) {
      $form['message'] = [
        '#markup' => $this->t('All of your projects are up to date.'),
      ];
      return $form;
    }

    $headers = [
      'title' => [
        
$text = $request->query->get('text');
    $uuid = $request->query->get('uuid');
    if ($text == '' || $uuid == '') {
      throw new NotFoundHttpException();
    }

    $build = [
      '#type' => 'processed_text',
      '#text' => $text,
      '#format' => $filter_format->id(),
    ];
    $html = $this->renderer->renderPlain($build);

    // Load the media item so we can embed the label in the response, for use     // in an ARIA label.     $headers = [];
    if ($media = $this->entityRepository->loadEntityByUuid('media', $uuid)) {
      $headers['Drupal-Media-Label'] = $this->entityRepository->getTranslationFromContext($media)->label();
    }

    // Note that we intentionally do not use:     // - \Drupal\Core\Cache\CacheableResponse because caching it on the server     // side is wasteful, hence there is no need for cacheability metadata.

    $element['#default_value'] = $items[$delta]->getValue() + $defaults;

    $default_fids = $element['#extended'] ? $element['#default_value']['fids'] : $element['#default_value'];
    if (empty($default_fids)) {
      $file_upload_help = [
        '#theme' => 'file_upload_help',
        '#description' => $element['#description'],
        '#upload_validators' => $element['#upload_validators'],
        '#cardinality' => $cardinality,
      ];
      $element['#description'] = \Drupal::service('renderer')->renderPlain($file_upload_help);
      $element['#multiple'] = $cardinality != 1 ? TRUE : FALSE;
      if ($cardinality != 1 && $cardinality != -1) {
        $element['#element_validate'] = [[static::class, 'validateMultipleCount']];
      }
    }

    return $element;
  }

  /** * {@inheritdoc} */

  protected function renderHtmlResponseAttachmentPlaceholders(HtmlResponse $response, array $placeholders, array $variables) {
    $content = $response->getContent();
    foreach ($placeholders as $type => $placeholder) {
      if (isset($variables[$type])) {
        $content = str_replace($placeholder$this->renderer->renderPlain($variables[$type])$content);
      }
    }
    $response->setContent($content);
  }

  /** * Sets headers on a response object. * * @param \Drupal\Core\Render\HtmlResponse $response * The HTML response to update. * @param array $headers * The headers to set, as an array. The items in this array should be as * follows: * - The header name. * - The header value. * - (optional) Whether to replace a current value with the new one, or add * it to the others. If the value is not replaced, it will be appended, * resulting in a header like this: 'Header: value1,value2' */
    $term = $entity_manager->getStorage('taxonomy_term')->create([
      'vid' => $vocabulary->id(),
      'name' => 'Foo',
    ]);

    // Confirm we can get the view of unsaved term.     $render_array = $entity_manager->getViewBuilder('taxonomy_term')
      ->view($term);
    $this->assertNotEmpty($render_array, 'Term view builder is built.');

    // Confirm we can render said view.     $rendered = \Drupal::service('renderer')->renderPlain($render_array);
    $this->assertNotEmpty(trim($rendered), 'Term is able to be rendered.');
  }

  /** * @covers \Drupal\taxonomy\TermStorage::deleteTermHierarchy * @group legacy */
  public function testDeleteTermHierarchyDeprecation(): void {
    $vocabulary = $this->createVocabulary();
    $term = $this->createTerm($vocabulary);

    

        sort($change_list);
        $message = [
          [
            '#markup' => $this->t('The following items in your active configuration have changes since the last import that may be lost on the next import.'),
          ],
          [
            '#theme' => 'item_list',
            '#items' => $change_list,
          ],
        ];
        $this->messenger()->addWarning($this->renderer->renderPlain($message));
      }
    }

    // Store the comparer for use in the submit.     $form_state->set('storage_comparer', $storage_comparer);

    // Add the AJAX library to the form for dialog support.     $form['#attached']['library'][] = 'core/drupal.dialog.ajax';

    foreach ($storage_comparer->getAllCollectionNames() as $collection) {
      if ($collection != StorageInterface::DEFAULT_COLLECTION) {
        


  /** * @covers ::render * @covers ::doRender */
  public function testRenderAccessCacheabilityDependencyInheritance() {
    $build = [
      '#access' => AccessResult::allowed()->addCacheContexts(['user']),
    ];

    $this->renderer->renderPlain($build);

    $this->assertEqualsCanonicalizing(['languages:language_interface', 'theme', 'user']$build['#cache']['contexts']);
  }

  /** * Tests rendering same render array twice. * * Tests that a first render returns the rendered output and a second doesn't * because of the #printed property. Also tests that correct metadata has been * set for re-rendering. * * @covers ::render * @covers ::doRender * * @dataProvider providerRenderTwice */
// @todo Consider using 'fetch_failures' from the 'update' collection       // in the key_value_expire service for this?       $fetch_failed = FALSE;
      foreach ($build['#data'] as $project) {
        if ($project['status'] === UpdateFetcherInterface::NOT_FETCHED) {
          $fetch_failed = TRUE;
          break;
        }
      }
      if ($fetch_failed) {
        $message = ['#theme' => 'update_fetch_error_message'];
        $this->messenger()->addError($this->renderer->renderPlain($message));
      }
    }
    return $build;
  }

  /** * Manually checks the update status without the use of cron. */
  public function updateStatusManually() {
    $this->updateManager->refreshUpdateData();
    $batch_builder = (new BatchBuilder())
      
'entity_id' => $node->id(),
      'entity_type' => 'node',
      'comment_type' => 'default',
      'pid' => $comment1,
    ])->save();

    // Render the comments.     $renderer = \Drupal::service('renderer');
    $comments = $comment_storage->loadMultiple();
    foreach ($comments as $comment) {
      $built = $this->buildEntityView($comment, 'full', NULL);
      $renderer->renderPlain($built);
    }

    // Make comment 2 an orphan by setting the property to an invalid value.     \Drupal::database()->update('comment_field_data')
      ->fields([$property => 10])
      ->condition('cid', 2)
      ->execute();
    $comment_storage->resetCache();
    $node_storage->resetCache();

    // Render the comments with an orphan comment.

  protected function doSearchExcerpt($keys$render_array$langcode = NULL) {
    $render_array = search_excerpt($keys$render_array$langcode);
    $text = \Drupal::service('renderer')->renderPlain($render_array);
    // The search_excerpt() function adds some extra spaces -- not     // important for HTML formatting or this test. Remove these for comparison.     return preg_replace('| +|', ' ', $text);
  }

}
Home | Imprint | This part of the site doesn't use cookies.