/** * {@inheritdoc} */ public function getCacheContexts() { // The block by itself doesn't really vary by user, but some of its // implementations are (collection module, I'm looking at you). For the sake // of semplicity, we add the user context here already. $contexts = parent::getCacheContexts(); return Cache::mergeContexts($contexts, ['user']); }
/** * CircleBreadcrumbs constructor. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, MenuLinkManagerInterface $link, MenuActiveTrailInterface $active, $link_tree) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->linkManager = $link; $this->active = $active; $this->linkTree = $link_tree; }
/** * {@inheritdoc} */ public function blockForm($form, FormStateInterface $form_state) { $form = parent::blockForm($form, $form_state); $config = $this->getConfiguration(); $form['hello_block_settings'] = array('#type' => 'textfield', '#title' => $this->t('Who'), '#description' => $this->t('Who do you want to say hello to?'), '#default_value' => isset($config['hello_block_settings']) ? $config['hello_block_settings'] : ''); return $form; }
/** * Constructs an SimplenewsSubscriptionBlock object. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Entity\EntityStorageInterface; $newsletterStorage * The storage object for newsletters. * @param \Drupal\Core\Form\FormBuilderInterface $formBuilder * The form builder object. * @param \Drupal\Core\Entity\Query\QueryInterface $newsletterQuery * The entity query object for newsletters. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager, FormBuilderInterface $formBuilder, QueryInterface $newsletterQuery) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityManager = $entity_manager; $this->formBuilder = $formBuilder; $this->newsletterQuery = $newsletterQuery; }
/** * Creates a HelpBlock instance. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Symfony\Component\HttpFoundation\Request $request * The current request. * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler * The module handler. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The current route match. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request, ModuleHandlerInterface $module_handler, RouteMatchInterface $route_match) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->request = $request; $this->moduleHandler = $module_handler; $this->routeMatch = $route_match; }
/** * {@inheritdoc} */ public function blockForm($form, FormStateInterface $form_state) { $form = parent::blockForm($form, $form_state); // Add a form field to the existing block configuration form. $form['name'] = array('#type' => 'textfield', '#title' => t('Your Name')); return $form; }
/** * Overrides \Drupal\Core\Block\BlockBase::blockForm(). */ public function blockForm($form, FormStateInterface $form_state) { $form = parent::blockForm($form, $form_state); // Retrieve existing configuration for this block. $config = $this->getConfiguration(); // Add a form field to the existing block configuration form. $form['flickr_items'] = array('#type' => 'select', '#title' => t('Number of items'), '#options' => array(10 => 10, 12 => 12, 15 => 15, 16 => 16, 18 => 18, 20 => 20), '#description' => t('Number of items that will be shown in the slideshow.'), '#default_value' => isset($config['flickr_items']) ? $config['flickr_items'] : ''); // $config = $this->configuration; // $defaults = $this->defaultConfiguration(); // $form['flickr_items'] = array( // '#type' => 'select', // '#title' => t('Number of items'), // '#options' => array( // 10 => 10, // 12 => 12, // 15 => 15, // 16 => 16, // 18 => 18, // 20 => 20 // ), // '#description' => t('This number of items will be shown in the Flickr block'), // '#default_value' => $config['flickr_items'], // ); // return $form; }
/** * {@inheritdoc} */ protected function blockAccess(AccountInterface $account) { if ($this->getContextValue('user') instanceof UserInterface) { drupal_set_message('User context found.'); } return parent::blockAccess($account); }
/** * Construct. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * @param mixed $plugin_definition * @param \Drupal\Core\Entity\EntityManager $entity_manager * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query * @param \Drupal\Core\Entity\EntityFormBuilder $entity_form_builder */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManager $entity_manager, QueryFactory $entity_query, EntityFormBuilder $entity_form_builder) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entity_manager = $entity_manager; $this->entity_query = $entity_query; $this->entity_form_builder = $entity_form_builder; }
/** * Construct. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param string $plugin_definition * The plugin implementation definition. * * Add type-hinted parameters for any services to be injected into this class * following the normal parameters. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManager $entity_manager, QueryFactory $entity_query) { parent::__construct($configuration, $plugin_id, $plugin_definition); // Make each of injected service available as a variable in the class. $this->entity_manager = $entity_manager; $this->entity_query = $entity_query; }
/** * {@inheritdoc} */ public function blockForm($form, &$form_state) { $form = parent::blockForm($form, $form_state); $config = $this->getConfiguration(); $form['demo_block_settings'] = array('#type' => 'textfield', '#title' => $this->t('Who'), '#description' => $this->t('Our custom block'), '#default_value' => isset($config['demo_block_settings']) ? $config['demo_block_settings'] : ''); return $form; }
/** * Constructs a new NodeFormBlock plugin * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Entity\EntityManagerInterface $entityManger * The entity manager. * @param \Drupal\Core\Entity\EntityFormBuilderInterface $entityFormBuilder * The entity form builder. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entityManager, EntityFormBuilderInterface $entityFormBuilder) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->setConfiguration($configuration); $this->entityManager = $entityManager; $this->entityFormBuilder = $entityFormBuilder; }
/** * Constructs RecentContent class. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param string $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Entity\Query\QueryFactory * The entity query factory. * @param EntityTypeManagerInterface $entity_type_manager * The entity type manager. * @param \Drupal\Core\Render\RendererInterface * The renderer. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, QueryFactory $entity_query, EntityTypeManagerInterface $entity_type_manager, RendererInterface $renderer) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityQuery = $entity_query; $this->entityTypeManager = $entity_type_manager; $this->renderer = $renderer; }
/** * Constructs a new SwitchUserBlock object. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Session\AccountInterface $current_user * Current user. * @param \Drupal\Core\Entity\EntityStorageInterface $user_storage * The user storage. * @param \Drupal\Core\Form\FormBuilderInterface $form_builder * The form builder service. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountInterface $current_user, EntityStorageInterface $user_storage, FormBuilderInterface $form_builder) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->formBuilder = $form_builder; $this->currentUser = $current_user; $this->userStorage = $user_storage; }
/** * Creates a NodeBlock instance. * * @param array $configuration * @param string $plugin_id * @param mixed $plugin_definition * @param EntityManagerInterface $entity_manager */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->viewBuilder = $entity_manager->getViewBuilder('node'); $this->nodeStorage = $entity_manager->getStorage('node'); $this->node = $entity_manager->getStorage('node')->load($this->getDerivativeId()); }
/** * Constructs a new BookNavigationBlock instance. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Symfony\Component\HttpFoundation\RequestStack $request_stack * The request stack object. * @param \Drupal\book\BookManagerInterface $book_manager * The book manager. * @param \Drupal\Core\Entity\EntityStorageInterface $node_storage * The node storage. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, RequestStack $request_stack, BookManagerInterface $book_manager, EntityStorageInterface $node_storage) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->requestStack = $request_stack; $this->bookManager = $book_manager; $this->nodeStorage = $node_storage; }
/** * Constructs a new DisqusBaseBlock. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin ID for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The current route match. * @param \Drupal\disqus\DisqusCommentManager $disqus_manager * The disqus comment manager object. * @param \Drupal\Core\Session\AccountInterface $current_user * The account for which view access should be checked. * @param \Drupal\Core\Config\ImmutableConfig $disqus_config * Disqus config object. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $route_match, DisqusCommentManager $disqus_manager, AccountInterface $current_user, ImmutableConfig $disqus_config) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->currentUser = $current_user; $this->disqusManager = $disqus_manager; $this->routeMatch = $route_match; $this->disqusConfig = $disqus_config; }
/** * Constructs a CollectionContentBlock object. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin ID for the plugin instance. * @param string $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Routing\RouteMatchInterface $current_route_match * The current route match service. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager. * @param \Drupal\Core\Plugin\Context\ContextProviderInterface $collection_context * The collection context. * @param \Drupal\og\MembershipManagerInterface $membership_manager * The OG membership manager. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $current_route_match, EntityTypeManagerInterface $entity_type_manager, ContextProviderInterface $collection_context, MembershipManagerInterface $membership_manager) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->currentRouteMatch = $current_route_match; $this->collection = $collection_context->getRuntimeContexts(['og'])['og']->getContextValue(); $this->entityTypeManager = $entity_type_manager; $this->membershipManager = $membership_manager; }
/** * Constructs a new DevelSwitchUser object. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Access\CsrfTokenGenerator $csrf_token_generator * @param \Drupal\Core\Form\FormBuilderInterface $form_builder * @param \Drupal\Core\Session\AccountProxyInterface $current_user */ public function __construct(array $configuration, $plugin_id, $plugin_definition, CsrfTokenGenerator $csrf_token_generator, FormBuilderInterface $form_builder, AccountProxyInterface $current_user, RedirectDestinationInterface $redirect_destination) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->csrfTokenGenerator = $csrf_token_generator; $this->formBuilder = $form_builder; $this->currentUser = $current_user; $this->redirectDestination = $redirect_destination; }
/** * {@inheritdoc} */ public function blockForm($form, FormStateInterface $form_state) { $form = parent::blockForm($form, $form_state); $config = $this->getConfiguration(); $form['unibuc_weather_api_key'] = array('#type' => 'textfield', '#title' => $this->t('Api Key'), '#description' => $this->t('Apy Key for openweathermap.org'), '#default_value' => isset($config['unibuc_weather_api_key']) ? $config['unibuc_weather_api_key'] : ''); $form['unibuc_weather_api_display'] = array('#type' => 'select', '#title' => $this->t('Display in'), '#options' => array('c' => 'C', 'f' => 'F'), '#description' => $this->t('How to display the temperature.'), '#default_value' => isset($config['unibuc_weather_api_display']) ? $config['unibuc_weather_api_display'] : ''); return $form; }
/** * Constructs a new BlockContentBlock. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin ID for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Block\BlockManagerInterface * The Plugin Block Manager. * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager service. * @param \Drupal\Core\Session\AccountInterface $account * The account for which view access should be checked. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, BlockManagerInterface $block_manager, EntityManagerInterface $entity_manager, AccountInterface $account, UrlGeneratorInterface $url_generator) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->blockManager = $block_manager; $this->entityManager = $entity_manager; $this->account = $account; $this->urlGenerator = $url_generator; }
/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); $form['cache']['#disabled'] = TRUE; $form['cache']['#description'] = $this->t("This block's maximum age cannot be configured, because it depends on the contents."); $form['cache']['max_age']['#value'] = Cache::PERMANENT; return $form; }
/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); // @see ::getCacheMaxAge() $form['cache']['#description'] = $this->t('This block is cacheable forever, it is not configurable.'); $form['cache']['max_age']['#value'] = Cache::PERMANENT; $form['cache']['max_age']['#disabled'] = TRUE; return $form; }
/** * {@inheritdoc} */ public function blockForm($form, FormStateInterface $form_state) { $form = parent::blockForm($form, $form_state); // Retrieve existing configuration for this block. $config = $this->getConfiguration(); // Add a form field to the existing block configuration form. $form['hello_text'] = array('#type' => 'textfield', '#title' => t('Hello text'), '#default_value' => isset($config['hello_text']) ? $config['hello_text'] : ''); return $form; }
/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); // The main content block is never cacheable, because it may be dynamic. $form['cache']['#disabled'] = TRUE; $form['cache']['#description'] = t('This block is never cacheable, it is not configurable.'); $form['cache']['max_age']['#value'] = 0; return $form; }
/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); // @see ::isCacheable() $form['cache']['#disabled'] = TRUE; $form['cache']['#description'] = t('This block is never cacheable, it is not configurable.'); $form['cache']['max_age']['#value'] = 0; return $form; }
/** * Constructs a SolutionContentBlock. * * @param array $configuration * A configuration array containing information about the plugin instance. * @param string $plugin_id * The plugin_id for the plugin instance. * @param string $plugin_definition * The plugin implementation definition. * @param \Drupal\Core\Routing\RouteMatchInterface $current_route_match * The route matcher. * @param \Drupal\Core\Entity\EntityManager $entity_manager * The deprecated entity manager. * @param \Drupal\Core\Plugin\Context\ContextProviderInterface $solution_context * The context provider for the solution context. * * @todo EntityManager is deprecated. Use EntityTypeManager instead. * * @see https://webgate.ec.europa.eu/CITnet/jira/browse/ISAICP-2669 */ public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteMatchInterface $current_route_match, EntityManager $entity_manager, ContextProviderInterface $solution_context) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->currentRouteMatch = $current_route_match; if (!empty($solution_context->getRuntimeContexts(['solution'])['solution'])) { $this->solution = $solution_context->getRuntimeContexts(['solution'])['solution']->getContextValue(); } $this->entityManager = $entity_manager; }
/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); // The 'Powered by Drupal' block is permanently cacheable, because its // contents can never change. $form['cache']['#disabled'] = TRUE; $form['cache']['max_age']['#value'] = Cache::PERMANENT; $form['cache']['#description'] = $this->t('This block is always cached forever, it is not configurable.'); return $form; }
/** * {@inheritdoc} */ public function blockForm($form, FormStateInterface $form_state) { $form = parent::blockForm($form, $form_state); // Retrieve existing configuration for this block. $config = $this->getConfiguration(); // Add a form field to the existing block configuration form. $form['slideshow_items'] = array('#type' => 'select', '#title' => t('Number of items'), '#options' => array(3 => 3, 5 => 5, 7 => 7, 9 => 9, 11 => 11, 13 => 13, 15 => 15, 17 => 17), '#description' => t('Number of items that will be shown in the slideshow.'), '#default_value' => isset($config['slideshow_items']) ? $config['slideshow_items'] : ''); $form['slideshow_order'] = array('#type' => 'select', '#title' => t('Order by'), '#options' => array('created ' => t('Creation date'), 'changed' => t('Date of last change')), '#description' => t('By which date the items will be ordered in the slideshow block'), '#default_value' => isset($config['slideshow_order']) ? $config['slideshow_order'] : ''); return $form; }
/** * MegaMenuBlock constructor. * * {@inheritdoc} * * @param EntityTypeManagerInterface $entityTypeManager * The Drupal entity type manager. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entityTypeManager, MenuLinkTreeInterface $menuLinkTree, LayoutPluginManagerInterface $layoutPluginManager, ContextHandlerInterface $contextHandler, ContextRepositoryInterface $contextRepository, AccountInterface $account) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeManager = $entityTypeManager; $this->menuLinkTree = $menuLinkTree; $this->layoutPluginManager = $layoutPluginManager; $this->contextHandler = $contextHandler; $this->contextRepository = $contextRepository; $this->account = $account; }