SliderBlock.php in Image sliders 8
File
src/Plugin/Derivative/SliderBlock.php
View source
<?php
namespace Drupal\image_slider\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Database\Connection;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SliderBlock extends DeriverBase implements ContainerDeriverInterface {
protected $database;
public function __construct(Connection $database) {
$this->database = $database;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('database'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
$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;
}
}
Classes
Name |
Description |
SliderBlock |
Provides a form for generating multiple block. |