You are here

public function CreditMessaging::build in Commerce PayPal 8

Builds and returns the renderable array for this block plugin.

If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).

Return value

array A renderable array representing the content of the block.

Overrides BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

src/Plugin/Block/CreditMessaging.php, line 175

Class

CreditMessaging
Provides a PayPal credit messaging block.

Namespace

Drupal\commerce_paypal\Plugin\Block

Code

public function build() {
  $element = [
    '#type' => 'html_tag',
    '#tag' => 'div',
    '#attributes' => [
      'data-pp-message' => '',
      'data-pp-placement' => $this->configuration['placement'],
      'data-pp-style-layout' => $this->configuration['style'],
    ],
    '#attached' => [
      'library' => [
        'commerce_paypal/credit_messaging',
      ],
    ],
  ];
  if ($this->configuration['style'] == 'flex') {
    $element['#attributes'] += [
      'data-pp-style-color' => $this->configuration['color'],
      'data-pp-style-ratio' => $this->configuration['ratio'],
    ];
  }
  else {
    $element['#attributes'] += [
      'data-pp-style-logo-type' => $this->configuration['logo_type'],
      'data-pp-style-logo-position' => $this->configuration['logo_position'],
      'data-pp-style-text-size' => $this->configuration['text_size'],
      'data-pp-style-text-color' => $this->configuration['text_color'],
    ];
  }
  return $element;
}