You are here

public function RRSSBDemoBlock::build in Ridiculously Responsive Social Sharing Buttons 8.2

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 RRSSBBlock::build

See also

\Drupal\block\BlockViewBuilder

File

src/Plugin/Block/RRSSBDemoBlock.php, line 23

Class

RRSSBDemoBlock
Provides a 'RRSSB demo' block.

Namespace

Drupal\rrssb\Plugin\Block

Code

public function build() {

  // Start with config values from the specified button set.
  $config = $this
    ->getConfiguration();
  $button_set = \Drupal::entityTypeManager()
    ->getStorage('rrssb_button_set')
    ->load($config['button_set']);

  // Take the relevant parts from the configuration form.
  $form = \Drupal::service('entity.form_builder')
    ->getForm($button_set, "edit");
  foreach (Element::children($form) as $key) {
    if ($key != 'appearance' && $key != 'actions') {
      unset($form[$key]);
    }
  }
  unset($form['#submit']);
  unset($form['actions']['delete']);
  unset($form['actions']['submit']['#submit']);
  $form['actions']['submit']['#value'] = $this
    ->t('Update');
  $form['#attributes']['class'][] = 'rrssb-control';
  $form['#attached']['library'][] = 'rrssb/demo';
  return $form;
}