You are here

class SliderBlock in Image sliders 8

Same name in this branch
  1. 8 src/Plugin/Derivative/SliderBlock.php \Drupal\image_slider\Plugin\Derivative\SliderBlock
  2. 8 src/Plugin/Block/SliderBlock.php \Drupal\image_slider\Plugin\Block\SliderBlock

Provides a form for generating multiple block.

Hierarchy

Expanded class hierarchy of SliderBlock

File

src/Plugin/Derivative/SliderBlock.php, line 15

Namespace

Drupal\image_slider\Plugin\Derivative
View 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

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
SliderBlock::$database protected property The database connection.
SliderBlock::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
SliderBlock::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
SliderBlock::__construct public function Construct a MyFormatter object.