You are here

class SendinblueBlock in SendinBlue 8

Same name in this branch
  1. 8 src/Plugin/Derivative/SendinblueBlock.php \Drupal\sendinblue\Plugin\Derivative\SendinblueBlock
  2. 8 src/Plugin/Block/SendinblueBlock.php \Drupal\sendinblue\Plugin\Block\SendinblueBlock
Same name and namespace in other branches
  1. 8.2 src/Plugin/Derivative/SendinblueBlock.php \Drupal\sendinblue\Plugin\Derivative\SendinblueBlock

Provides block plugin definitions for sendinblue blocks.

Hierarchy

Expanded class hierarchy of SendinblueBlock

See also

\Drupal\sendinblue\Plugin\Block\SendinblueBlock

File

src/Plugin/Derivative/SendinblueBlock.php, line 17

Namespace

Drupal\sendinblue\Plugin\Derivative
View source
class SendinblueBlock extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * EntityTypeManagerInterface.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  private $entityTypeManager;

  /**
   * Block name.
   *
   * @var string
   */
  private $blockName;

  /**
   * {@inheritdoc}
   */
  public function __construct($blockName, EntityTypeManagerInterface $entityTypeManager) {
    $this->entityTypeManager = $entityTypeManager;
    $this->blockName = $blockName;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $blockName) {
    return new static($blockName, $container
      ->get('entity_type.manager'));
  }

  /**
   * Provide multiple blocks for sendinblue signup forms.
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $signups = $this->entityTypeManager
      ->getStorage(SendinblueManager::SENDINBLUE_SIGNUP_ENTITY)
      ->loadMultiple();
    foreach ($signups as $signup) {
      if ((int) $signup->mode->value == SendinblueManager::SENDINBLUE_SIGNUP_BLOCK || (int) $signup->mode->value == SendinblueManager::SENDINBLUE_SIGNUP_BOTH) {
        $this->derivatives[$signup->mcsId->value] = $base_plugin_definition;
        $this->derivatives[$signup->mcsId->value]['admin_label'] = $this
          ->t('SendinBlue Subscription Form: @name', [
          '@name' => $signup->name->value,
        ]);
        $this->derivatives[$signup->mcsId->value]['mcsId'] = $signup->mcsId->value;
      }
    }
    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
SendinblueBlock::$blockName private property Block name.
SendinblueBlock::$entityTypeManager private property EntityTypeManagerInterface.
SendinblueBlock::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
SendinblueBlock::getDerivativeDefinitions public function Provide multiple blocks for sendinblue signup forms. Overrides DeriverBase::getDerivativeDefinitions
SendinblueBlock::__construct public function
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.