You are here

bynder_lightning.install in Bynder 8

Install, uninstall and update hooks for Bynder Lighting module.

File

modules/lightning/bynder_lightning.install
View source
<?php

/**
 * @file
 * Install, uninstall and update hooks for Bynder Lighting module.
 */

/**
 * Implements hook_requirements().
 */
function bynder_lightning_requirements($phase) {
  if ($phase == 'install' && !\Drupal::moduleHandler()
    ->moduleExists('lightning_media')) {
    return [
      'bynder_lightning' => [
        'title' => 'Lightning media is disabled',
        'description' => t('Bynder Lightning integration requires Lightning media module to be enabled.'),
        'severity' => REQUIREMENT_ERROR,
      ],
    ];
  }
}

/**
 * Implements hook_install().
 */
function bynder_lightning_install() {

  /** @var \Drupal\entity_browser\Entity\EntityBrowser $browser */
  $browser = \Drupal::entityTypeManager()
    ->getStorage('entity_browser')
    ->load('media_browser');
  $widget_manager = \Drupal::getContainer()
    ->get('plugin.manager.entity_browser.widget');
  $bynder_upload = $widget_manager
    ->getDefinition('bynder_upload');
  $bynder_search = $widget_manager
    ->getDefinition('bynder_search');
  $browser
    ->addWidget([
    'id' => $bynder_upload['id'],
    'label' => $bynder_upload['label'],
    'weight' => -10,
    'settings' => [
      'media_bundle' => 'bynder',
    ],
  ]);
  $browser
    ->addWidget([
    'id' => $bynder_search['id'],
    'label' => $bynder_search['label'],
    'weight' => -20,
    'settings' => [
      'media_bundle' => 'bynder',
    ],
  ]);
  $browser
    ->save();
}