You are here

protected function InsertFileWidgetUtility::attachJavaScript in Insert 8

Parameters

array $element:

string $fieldType:

array $styleClasses:

Return value

array

1 call to InsertFileWidgetUtility::attachJavaScript()
InsertFileWidgetUtility::process in src/Utility/InsertFileWidgetUtility.php
Form API callback: Processes a file field element.

File

src/Utility/InsertFileWidgetUtility.php, line 289

Class

InsertFileWidgetUtility

Namespace

Drupal\insert\Utility

Code

protected function attachJavaScript($element, $fieldType, $styleClasses) {
  $config = \Drupal::config('insert.config');
  $element['#attached']['drupalSettings']['insert'] = [
    'fileDirectoryPath' => \Drupal::config('system.file')
      ->get('default_scheme'),
    // These CSS classes will be retained from being dumped by CKEditor when
    // applying CKEditor styles using CKEditor's style drop-down.
    'classes' => [
      $fieldType => [
        'insertClass' => $config
          ->get('css_classes.' . $fieldType),
        'styleClass' => join(' ', $styleClasses),
      ],
    ],
  ];
  $element['#attached']['library'][] = 'insert/insert';
  $insertSettings = [
    'fields' => static::$insert_fields,
  ];
  $element['#attached']['drupalSettings']['insert']['widgets'] = [
    $fieldType => $insertSettings,
  ];
  return $element;
}