X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fplugin%2Fblock.twig;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Ftemplates%2Fd8%2Fplugin%2Fblock.twig;h=be9280e2dc8f1b034a1e309a87eb1e203884dfee;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/chi-teck/drupal-code-generator/templates/d8/plugin/block.twig b/vendor/chi-teck/drupal-code-generator/templates/d8/plugin/block.twig new file mode 100644 index 000000000..be9280e2d --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/templates/d8/plugin/block.twig @@ -0,0 +1,116 @@ +routeMatch = $route_match; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('current_route_match') + ); + } + + /** + * {@inheritdoc} + */ + public function defaultConfiguration() { + return [ + 'content' => $this->t('Hello world!'), + ]; + } + + /** + * {@inheritdoc} + */ + public function blockForm($form, FormStateInterface $form_state) { + $form['content'] = [ + '#type' => 'textarea', + '#title' => $this->t('Block content'), + '#default_value' => $this->configuration['content'], + ]; + return $form; + } + + /** + * {@inheritdoc} + */ + public function blockSubmit($form, FormStateInterface $form_state) { + $this->configuration['content'] = $form_state->getValue('content'); + } + + /** + * {@inheritdoc} + * + * @DCG Remove this method of you do not need any access restrictions. + */ + protected function blockAccess(AccountInterface $account) { + $route_name = $this->routeMatch->getRouteName(); + // Display the block only for anonymous users. + if ($account->isAnonymous() && $route_name != 'user.register') { + return AccessResult::allowed() + ->addCacheContexts(['route.name', 'user.roles:anonymous']); + } + return AccessResult::forbidden(); + } + + /** + * {@inheritdoc} + */ + public function build() { + $build['content'] = [ + '#markup' => $this->configuration['content'], + ]; + return $build; + } + +}