You are here

public function Subscriptions::build in Message Subscribe 8

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

message_subscribe_ui/src/Plugin/Block/Subscriptions.php, line 128

Class

Subscriptions
An entity subscriptions block.

Namespace

Drupal\message_subscribe_ui\Plugin\Block

Code

public function build() {
  if (!($entity = $this
    ->getCurrentEntity()) || !$this
    ->hasSubscribableEntites($entity)) {

    // Not on an entity page. Ensure the block is only cached for this route.
    return [
      '#cache' => [
        'contexts' => [
          'user',
          'url.path',
        ],
      ],
    ];
  }
  return $this->formBuilder
    ->getForm($this);
}