You are here

function media_acquiadam_example_install in Media: Acquia DAM 8

Implements hook_install().

File

modules/media_acquiadam_example/media_acquiadam_example.install, line 13
Drupal install and update hooks.

Code

function media_acquiadam_example_install() {

  // If we're using Lightning Media we should add the DAM browser by default so
  // there is less initial setup required from the end user.
  if (Drupal::moduleHandler()
    ->moduleExists('lightning_media')) {

    /** @var \Drupal\entity_browser\EntityBrowserInterface $browser */
    $browser = EntityBrowser::load('media_browser');
    if (!empty($browser)) {
      $widgets = [
        'acquia_dam_asset' => [
          'label' => t('Acquia DAM Asset'),
          'submit_text' => t('Select assets'),
        ],
        'acquia_dam_audio' => [
          'label' => t('Acquia DAM Audio'),
          'submit_text' => t('Select audio'),
        ],
        'acquia_dam_document' => [
          'label' => t('Acquia DAM Documents'),
          'submit_text' => t('Select documents'),
        ],
        'acquia_dam_image' => [
          'label' => t('Acquia DAM Images'),
          'submit_text' => t('Select images'),
        ],
        'acquia_dam_video' => [
          'label' => t('Acquia DAM Video'),
          'submit_text' => t('Select video'),
        ],
      ];
      $weight = 10;
      foreach ($widgets as $type => $text) {
        $browser
          ->addWidget([
          'id' => 'acquiadam',
          'label' => $text['label'],
          'weight' => $weight++,
          'settings' => [
            'media_type' => $type,
            'submit_text' => $text['submit_text'],
          ],
        ]);
      }
      $browser
        ->save();
    }
  }
}