class BootstrapLayoutDeriver in Bootstrap Layout Builder 2.x
Same name and namespace in other branches
- 1.x src/Plugin/Deriver/BootstrapLayoutDeriver.php \Drupal\bootstrap_layout_builder\Plugin\Deriver\BootstrapLayoutDeriver
Makes a bootstrap layout for each layout config entity.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\bootstrap_layout_builder\Plugin\Deriver\BootstrapLayoutDeriver implements ContainerDeriverInterface uses StringTranslationTrait
Expanded class hierarchy of BootstrapLayoutDeriver
File
- src/
Plugin/ Deriver/ BootstrapLayoutDeriver.php, line 16
Namespace
Drupal\bootstrap_layout_builder\Plugin\DeriverView source
class BootstrapLayoutDeriver extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a new BootstrapLayoutDeriver object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$layouts = $this->entityTypeManager
->getStorage('blb_layout')
->getQuery()
->sort('number_of_columns', 'ASC')
->execute();
if ($layouts) {
foreach ($layouts as $layout_id) {
$layout = $this->entityTypeManager
->getStorage('blb_layout')
->load($layout_id);
$this->derivatives[$layout
->id()] = new LayoutDefinition([
'class' => BootstrapLayout::class,
'label' => $layout
->label(),
'id' => $layout
->id(),
'category' => 'Bootstrap',
'regions' => $this
->getRegions($layout
->getNumberOfColumns()),
'theme_hook' => 'blb_section',
'icon_map' => $this
->getIconMap($layout
->getNumberOfColumns()),
]);
}
}
return $this->derivatives;
}
/**
* Convert intger to number in letters.
*
* @param int $num
* The number that needed to be converted.
*
* @return string
* The number in letters.
*/
private function formatNumberInLetters(int $num) {
$numbers = [
1 => "one",
2 => "two",
3 => "three",
4 => "four",
5 => "five",
6 => "six",
7 => "seven",
8 => "eight",
9 => "nine",
10 => "ten",
11 => "eleven",
12 => "twelve",
];
return $numbers[$num];
}
/**
* Get the formated array of row regions based on columns count.
*
* @param int $columns_count
* The count of row columns.
*
* @return array
* The row columns 'regions'.
*/
private function getRegions(int $columns_count) {
$regions = [];
for ($i = 1; $i <= $columns_count; $i++) {
$key = 'blb_region_col_' . $i;
$regions[$key] = [
'label' => $this
->t('Col') . ' ' . $i,
];
}
return $regions;
}
/**
* Get the icon map array based on columns_count.
*
* @param int $columns_count
* The count of row columns.
*
* @return array
* The icon map array.
*/
private function getIconMap(int $columns_count) {
$row = [];
for ($i = 1; $i <= $columns_count; $i++) {
$row[] = 'square_' . $this
->formatNumberInLetters($i);
}
$icon_map = [
$row,
];
return $icon_map;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BootstrapLayoutDeriver:: |
protected | property | The entity type manager. | |
BootstrapLayoutDeriver:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
BootstrapLayoutDeriver:: |
private | function | Convert intger to number in letters. | |
BootstrapLayoutDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
BootstrapLayoutDeriver:: |
private | function | Get the icon map array based on columns_count. | |
BootstrapLayoutDeriver:: |
private | function | Get the formated array of row regions based on columns count. | |
BootstrapLayoutDeriver:: |
public | function | Constructs a new BootstrapLayoutDeriver object. | |
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |