BlockDescription.php in Display Suite 8.3
File
src/Plugin/DsField/Block/BlockDescription.php
View source
<?php
namespace Drupal\ds\Plugin\DsField\Block;
use Drupal\ds\Plugin\DsField\DsFieldBase;
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
class BlockDescription extends DsFieldBase {
public function build() {
$config = $this
->getConfiguration();
$output = $this
->entity()
->label();
if (empty($output)) {
return [];
}
$output = Html::escape($output);
if (!empty($config['wrapper'])) {
$wrapper = Html::escape($config['wrapper']);
$class = !empty($config['class']) ? ' class="' . Html::escape($config['class']) . '"' : '';
$output = '<' . $wrapper . $class . '>' . $output . '</' . $wrapper . '>';
}
return [
'#markup' => $output,
];
}
public function settingsForm($form, FormStateInterface $form_state) {
$config = $this
->getConfiguration();
$settings['wrapper'] = [
'#type' => 'textfield',
'#title' => 'Wrapper',
'#default_value' => $config['wrapper'],
'#description' => $this
->t('Eg: h1, h2, p'),
];
$settings['class'] = [
'#type' => 'textfield',
'#title' => 'Class',
'#default_value' => $config['class'],
'#description' => $this
->t('Put a class on the wrapper. Eg: block-title'),
];
return $settings;
}
public function settingsSummary($settings) {
$config = $this
->getConfiguration();
$summary = [];
$summary[] = 'Wrapper: ' . $config['wrapper'];
if (!empty($config['class'])) {
$summary[] = 'Class: ' . $config['class'];
}
return $summary;
}
public function defaultConfiguration() {
$configuration = [
'wrapper' => 'h2',
'class' => '',
];
return $configuration;
}
protected function entityRenderKey() {
return 'label';
}
}