You are here

public function AppViewBuilder::buildMultiple in Apigee Edge 8

Builds multiple entities' views; augments entity defaults.

This function is assigned as a #pre_render callback in ::viewMultiple().

By delaying the building of an entity until the #pre_render processing in drupal_render(), the processing cost of assembling an entity's renderable array is saved on cache-hit requests.

Parameters

array $build_list: A renderable array containing build information and context for an entity view.

Return value

array The updated renderable array.

Overrides EntityViewBuilder::buildMultiple

See also

\Drupal\Core\Render\RendererInterface::render()

File

src/Entity/AppViewBuilder.php, line 34

Class

AppViewBuilder
Common app view builder for developer- and company (team) apps.

Namespace

Drupal\apigee_edge\Entity

Code

public function buildMultiple(array $build_list) {
  $results = parent::buildMultiple($build_list);
  foreach (Element::children($results) as $key) {

    /** @var \Drupal\apigee_edge\Entity\AppInterface $app */
    $app = $results[$key]["#{$this->entityTypeId}"];

    // If the callback field is visible, display an error message if the
    // callback url field value does not contain a valid URI.
    if (array_key_exists('callbackUrl', $results[$key]) && !empty($app
      ->getCallbackUrl()) && $app
      ->getCallbackUrl() !== $app
      ->get('callbackUrl')->value) {
      try {
        Url::fromUri($app
          ->getCallbackUrl());
      } catch (\Exception $exception) {
        $results[$key]['callback_url_error'] = [
          '#theme' => 'status_messages',
          '#message_list' => [
            'warning' => [
              $this
                ->t('The @field value should be fixed. @message', [
                '@field' => $app
                  ->getFieldDefinition('callbackUrl')
                  ->getLabel(),
                '@message' => $exception
                  ->getMessage(),
              ]),
            ],
          ],
          // Display it on the top of the view.
          '#weight' => -100,
        ];
      }
    }
  }
  return $results;
}