BackgroundImageBlock.php in Background Image 2.x
File
src/Plugin/Block/BackgroundImageBlock.php
View source
<?php
namespace Drupal\background_image\Plugin\Block;
use Drupal\background_image\BackgroundImageManager;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
class BackgroundImageBlock extends BlockBase {
protected function baseConfigurationDefaults() {
$defaults = parent::baseConfigurationDefaults();
$defaults['label_display'] = 'hidden';
return $defaults;
}
public function build() {
$build = [];
$background_image_manager = BackgroundImageManager::service();
if ($background_image = $background_image_manager
->getBackgroundImage()) {
$build = $background_image_manager
->view($background_image, 'image');
}
$build['#cache']['contexts'][] = 'user.permissions';
return $build;
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['label_display']['#access'] = FALSE;
return $form;
}
}
Classes
Name |
Description |
BackgroundImageBlock |
Plugin annotation
@Block(
id = "background_image",
admin_label = @Translation("Background Image"),
category = @Translation("Background Image")
) |