class SliderBlock in Image sliders 8
Same name in this branch
- 8 src/Plugin/Derivative/SliderBlock.php \Drupal\image_slider\Plugin\Derivative\SliderBlock
- 8 src/Plugin/Block/SliderBlock.php \Drupal\image_slider\Plugin\Block\SliderBlock
Provides a form for generating multiple block.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\image_slider\Plugin\Derivative\SliderBlock implements ContainerDeriverInterface
Expanded class hierarchy of SliderBlock
File
- src/
Plugin/ Derivative/ SliderBlock.php, line 15
Namespace
Drupal\image_slider\Plugin\DerivativeView source
class SliderBlock extends DeriverBase implements ContainerDeriverInterface {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* Construct a MyFormatter object.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection.
*/
public function __construct(Connection $database) {
$this->database = $database;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('database'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
// @todo might as well include your configuration here and assign a
// value.
$slider_data = [];
$slider_data = $this->database
->select('slider', 's')
->fields('s')
->execute()
->FetchAll();
if (is_array($slider_data) && count($slider_data) > 0) {
foreach ($slider_data as $val) {
$this->derivatives[$val->id] = $base_plugin_definition;
$this->derivatives[$val->id]['admin_label'] = $val->name;
}
}
else {
$slider_data = [
'0' => 'Slider Demo',
];
foreach ($slider_data as $key => $val) {
$this->derivatives[$key] = $base_plugin_definition;
$this->derivatives[$key]['admin_label'] = $val;
}
}
return $this->derivatives;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
SliderBlock:: |
protected | property | The database connection. | |
SliderBlock:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
SliderBlock:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
SliderBlock:: |
public | function | Construct a MyFormatter object. |