Commit 285effc8 authored by Joshua Sedler's avatar Joshua Sedler 🤸🏼 Committed by Julian Pustkuchen
Browse files

Issue #3270093 by Grevil, Anybody: Implement hook_requirements in combination...

Issue #3270093 by Grevil, Anybody: Implement hook_requirements in combination with composer "suggest" for "npm-asset" libraries
parent aef8e6c9
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@
    "issues": "https://www.drupal.org/project/issues/drowl_admin_dashboard",
    "source": "http://cgit.drupalcode.org/drowl_admin_dashboard"
  },
  "require": {
    "npm-asset/drowl-admin-iconset": "^1.0"
  "suggest": {
    "npm-asset/drowl-admin-iconset": "Required to use drupal/drowl_admin_dashboard. Expected version: ^1.0"
  }
}
+32 −0
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Install, update and uninstall functions for the drowl_admin_dashboard module.
 */

/**
 * Implements hook_requirements().
 */
function drowl_admin_dashboard_requirements($phase) {
  if ($phase != 'runtime') {
    return [];
  }
  $requirements = [];

  $drowlAdminIconsetLibrary = \Drupal::service('library.discovery')->getLibraryByName('drowl_admin_dashboard', 'admin_iconset');

  if (empty($drowlAdminIconsetLibrary)) {
    throw new Exception("Required libraries for the drowl_admin_dashboard module are not defined in the appropriate libraries.yml file.");
  }

  $drowlAdminIconsExist = file_exists(DRUPAL_ROOT . '/' . $drowlAdminIconsetLibrary['css'][0]['data']);

  $requirements['drowl_admin_iconset'] = [
    'title' => t('Drowl Admin Dashboard: Missing Drowl Admin Iconset library'),
    'value' => $drowlAdminIconsExist ? t('Installed') : t('Not installed'),
    'description' => $drowlAdminIconsExist ? '' : t('To use the drowl_admin_dashboard module, the drowl admin iconset library needs to be required via composer, using "composer require npm-asset/drowl-admin-iconset". NOTE, that you need to set up the "asset-packagist" repository in your projects composer.json file.<br>See <a href="https://www.drupal.org/docs/develop/using-composer/using-composer-to-install-drupal-and-manage-dependencies#third-party-libraries">here</a> on how to do it.'),
    'severity' => $drowlAdminIconsExist ? REQUIREMENT_OK : REQUIREMENT_ERROR,
  ];
  return $requirements;
}