Created
March 1, 2017 20:14
-
-
Save cyberlex404/6b76124a61c3869d4e13c3c1db321822 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace Drupal\bebooking\Plugin\Block; | |
| use Drupal\Core\Block\BlockBase; | |
| use Drupal\Core\Form\FormStateInterface; | |
| use Drupal\Core\Plugin\ContainerFactoryPluginInterface; | |
| use Symfony\Component\DependencyInjection\ContainerInterface; | |
| use Drupal\Core\Entity\EntityTypeManager; | |
| use Drupal\Core\Entity\Query\QueryFactory; | |
| /** | |
| * Provides a 'RoomCalendar' block. | |
| * | |
| * @Block( | |
| * id = "room_calendar", | |
| * admin_label = @Translation("Room calendar"), | |
| * ) | |
| */ | |
| class RoomCalendar extends BlockBase implements ContainerFactoryPluginInterface { | |
| /** | |
| * Drupal\Core\Entity\EntityTypeManager definition. | |
| * | |
| * @var \Drupal\Core\Entity\EntityTypeManager | |
| */ | |
| protected $entityTypeManager; | |
| /** | |
| * Drupal\Core\Entity\Query\QueryFactory definition. | |
| * | |
| * @var \Drupal\Core\Entity\Query\QueryFactory | |
| */ | |
| protected $entityQuery; | |
| /** | |
| * 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. | |
| */ | |
| public function __construct( | |
| array $configuration, | |
| $plugin_id, | |
| $plugin_definition, | |
| EntityTypeManager $entity_type_manager, | |
| QueryFactory $entity_query | |
| ) { | |
| parent::__construct($configuration, $plugin_id, $plugin_definition); | |
| $this->entityTypeManager = $entity_type_manager; | |
| $this->entityQuery = $entity_query; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { | |
| return new static( | |
| $configuration, | |
| $plugin_id, | |
| $plugin_definition, | |
| $container->get('entity_type.manager'), | |
| $container->get('entity.query') | |
| ); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function defaultConfiguration() { | |
| return [ | |
| 'color' => $this->t(''), | |
| ] + parent::defaultConfiguration(); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function blockForm($form, FormStateInterface $form_state) { | |
| $form['color'] = [ | |
| '#type' => 'color', | |
| '#title' => $this->t('Color'), | |
| '#description' => $this->t(''), | |
| '#default_value' => $this->configuration['color'], | |
| '#weight' => '0', | |
| ]; | |
| return $form; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function blockSubmit($form, FormStateInterface $form_state) { | |
| $this->configuration['color'] = $form_state->getValue('color'); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function build() { | |
| $build = []; | |
| $build['room_calendar_color']['#markup'] = '<p>' . $this->configuration['color'] . '</p>'; | |
| return $build; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment