You are here

public function Ng2Block::attachSettings in Decoupled Blocks 8

Attaches JavaScript settings required by the component.

Parameters

array $component: The component definition.

Return value

array Array of attachments.

Overrides PdbBlock::attachSettings

File

modules/pdb_ng2/src/Plugin/Block/Ng2Block.php, line 45

Class

Ng2Block
Exposes an Angular 2 component as a block.

Namespace

Drupal\pdb_ng2\Plugin\Block

Code

public function attachSettings(array $component) {
  $attached = parent::attachSettings($component);
  $machine_name = $component['machine_name'];
  $uuid = $this->configuration['uuid'];
  $attached['drupalSettings']['pdb']['ng2']['components']['instance-id-' . $uuid] = [
    'uri' => $component['path'],
    'element' => $machine_name,
  ];

  // Check if ng_class_name was defined.
  if (!empty($component['ng_class_name'])) {

    // Add "ngClassName" value.
    $attached['drupalSettings']['pdb']['ng2']['components']['instance-id-' . $uuid] += [
      'ngClassName' => $component['ng_class_name'],
    ];
  }
  $attached['drupalSettings']['pdb']['ng2']['module_path'] = drupal_get_path('module', 'pdb_ng2');
  $config_settings = \Drupal::config('pdb_ng2.settings');
  if (isset($config_settings)) {
    $attached['drupalSettings']['pdb']['ng2']['development_mode'] = $config_settings
      ->get('development_mode');
  }
  else {
    $attached['drupalSettings']['pdb']['ng2']['development_mode'] = TRUE;
  }
  return $attached;
}