X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;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=ab96052a9058961bc3013375114761109976d614;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=be9280e2dc8f1b034a1e309a87eb1e203884dfee;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website 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 index be9280e2d..ab96052a9 100644 --- a/vendor/chi-teck/drupal-code-generator/templates/d8/plugin/block.twig +++ b/vendor/chi-teck/drupal-code-generator/templates/d8/plugin/block.twig @@ -1,17 +1,26 @@ +{% import 'lib/di.twig' as di %} routeMatch = $route_match; +{{ di.assignment(services) }} } /** @@ -56,16 +60,18 @@ class {{ class }} extends BlockBase implements ContainerFactoryPluginInterface { $configuration, $plugin_id, $plugin_definition, - $container->get('current_route_match') +{{ di.container(services) }} ); } +{% endif %} +{% if configurable %} /** * {@inheritdoc} */ public function defaultConfiguration() { return [ - 'content' => $this->t('Hello world!'), + 'foo' => $this->t('Hello world!'), ]; } @@ -73,10 +79,10 @@ class {{ class }} extends BlockBase implements ContainerFactoryPluginInterface { * {@inheritdoc} */ public function blockForm($form, FormStateInterface $form_state) { - $form['content'] = [ + $form['foo'] = [ '#type' => 'textarea', - '#title' => $this->t('Block content'), - '#default_value' => $this->configuration['content'], + '#title' => $this->t('Foo'), + '#default_value' => $this->configuration['foo'], ]; return $form; } @@ -85,30 +91,27 @@ class {{ class }} extends BlockBase implements ContainerFactoryPluginInterface { * {@inheritdoc} */ public function blockSubmit($form, FormStateInterface $form_state) { - $this->configuration['content'] = $form_state->getValue('content'); + $this->configuration['foo'] = $form_state->getValue('foo'); } +{% endif %} +{% if access %} /** * {@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(); + // @DCG Evaluate the access condition here. + $condition = TRUE; + return AccessResult::allowedIf($condition); } +{% endif %} /** * {@inheritdoc} */ public function build() { $build['content'] = [ - '#markup' => $this->configuration['content'], + '#markup' => $this->t('It works!'), ]; return $build; }