You are here

public function GoogleCSEBlock::build in Google Custom Search Engine 8.3

Same name and namespace in other branches
  1. 8.2 src/Plugin/Block/GoogleCSEBlock.php \Drupal\google_cse\Plugin\Block\GoogleCSEBlock::build()

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

src/Plugin/Block/GoogleCSEBlock.php, line 90

Class

GoogleCSEBlock
Provides a 'Google CSE' block.

Namespace

Drupal\google_cse\Plugin\Block

Code

public function build() {
  $config = $this->configFactory
    ->get('search.page.google_cse_search');
  return [
    '#theme' => 'google_cse_results',
    '#form' => TRUE,
    '#markup' => 'search',
    '#attached' => [
      'library' => [
        'google_cse/googlecseWatermark',
      ],
      'drupalSettings' => [
        'googleCSE' => [
          'cx' => $config
            ->get('configuration')['cx'],
          'language' => google_cse_language(),
          'resultsWidth' => intval($config
            ->get('configuration')['results_width']),
          'domain' => $config
            ->get('configuration')['domain'],
        ],
      ],
    ],
  ];
}