Issue #3340712 by e0ipso, alexpott, larowlan, dww, _pratik_, catch, penyaskito, mherchel, pdureau, jonathanshaw, mglaman, idiaz.roncero, geek-merlin, ctrlADel, mrweiner, bnjmnm, longwave, guschilds, cosmicdreams, dreamleaf, ckrina, Gábor Hojtsy, lauriii, unstatu, markconroy, nod_: Add Single Directory Components as a new experimental module
2023-04-17 22:07:14 +00:00
< ? php
/**
* @ file
* Module implementation file .
*/
2024-03-27 21:19:28 +00:00
use Drupal\Core\Theme\ComponentPluginManager ;
use Drupal\Core\Plugin\Component ;
Issue #3340712 by e0ipso, alexpott, larowlan, dww, _pratik_, catch, penyaskito, mherchel, pdureau, jonathanshaw, mglaman, idiaz.roncero, geek-merlin, ctrlADel, mrweiner, bnjmnm, longwave, guschilds, cosmicdreams, dreamleaf, ckrina, Gábor Hojtsy, lauriii, unstatu, markconroy, nod_: Add Single Directory Components as a new experimental module
2023-04-17 22:07:14 +00:00
2024-03-27 21:19:28 +00:00
@ class_alias ( 'Drupal\Core\Render\Element' , 'Drupal\sdc\Utilities' );
@ class_alias ( 'Drupal\Core\Render\Element\ComponentElement' , 'Drupal\sdc\Element\ComponentElement' );
@ class_alias ( 'Drupal\Core\Render\Component\Exception\ComponentNotFoundException' , 'Drupal\sdc\Exception\ComponentNotFoundException' );
@ class_alias ( 'Drupal\Core\Render\Component\Exception\IncompatibleComponentSchema' , 'Drupal\sdc\Exception\IncompatibleComponentSchema' );
@ class_alias ( 'Drupal\Core\Render\Component\Exception\InvalidComponentDataException' , 'Drupal\sdc\Exception\InvalidComponentDataException' );
@ class_alias ( 'Drupal\Core\Render\Component\Exception\InvalidComponentException' , 'Drupal\sdc\Exception\InvalidComponentException' );
@ class_alias ( 'Drupal\Core\Theme\Component\ComponentMetadata' , 'Drupal\sdc\Component\ComponentMetadata' );
@ class_alias ( 'Drupal\Core\Theme\Component\ComponentValidator' , 'Drupal\sdc\Component\ComponentValidator' );
@ class_alias ( 'Drupal\Core\Theme\Component\SchemaCompatibilityChecker' , 'Drupal\sdc\Component\SchemaCompatibilityChecker' );
@ class_alias ( 'Drupal\Core\Plugin\Component' , 'Drupal\sdc\Plugin\Component' );
@ class_alias ( 'Drupal\Core\Plugin\Discovery\DirectoryWithMetadataDiscovery' , 'Drupal\sdc\Plugin\Discovery\DirectoryWithMetadataDiscovery' );
@ class_alias ( 'Drupal\Core\Plugin\Discovery\DirectoryWithMetadataPluginDiscovery' , 'Drupal\sdc\Plugin\Discovery\DirectoryWithMetadataPluginDiscovery' );
@ class_alias ( 'Drupal\Core\Plugin\Discovery\RegexRecursiveFilterIterator' , 'Drupal\sdc\Plugin\Discovery\RegexRecursiveFilterIterator' );
@ class_alias ( 'Drupal\Core\Template\ComponentNodeVisitor' , 'Drupal\sdc\Twig\ComponentNodeVisitor' );
@ class_alias ( 'Drupal\Core\Template\Loader\ComponentLoader' , 'Drupal\sdc\Twig\TwigComponentLoader' );
@ class_alias ( 'Drupal\Core\Theme\ComponentNegotiator' , 'Drupal\sdc\ComponentNegotiator' );
@ class_alias ( 'Drupal\Core\Theme\ComponentPluginManager' , 'Drupal\sdc\ComponentPluginManager' );
@ class_alias ( 'Drupal\Core\Theme\ExtensionType' , 'Drupal\sdc\ExtensionType' );
Issue #3340712 by e0ipso, alexpott, larowlan, dww, _pratik_, catch, penyaskito, mherchel, pdureau, jonathanshaw, mglaman, idiaz.roncero, geek-merlin, ctrlADel, mrweiner, bnjmnm, longwave, guschilds, cosmicdreams, dreamleaf, ckrina, Gábor Hojtsy, lauriii, unstatu, markconroy, nod_: Add Single Directory Components as a new experimental module
2023-04-17 22:07:14 +00:00
/**
* Implements hook_library_info_build () .
*/
function sdc_library_info_build () {
2024-03-27 21:19:28 +00:00
$deprecation_message = 'The %library_id% asset library is deprecated in Drupal 10.3.0 and will be removed in Drupal 11.0.0. Use the core/components.[component-id] library instead. See https://www.drupal.org/node/3410260' ;
Issue #3340712 by e0ipso, alexpott, larowlan, dww, _pratik_, catch, penyaskito, mherchel, pdureau, jonathanshaw, mglaman, idiaz.roncero, geek-merlin, ctrlADel, mrweiner, bnjmnm, longwave, guschilds, cosmicdreams, dreamleaf, ckrina, Gábor Hojtsy, lauriii, unstatu, markconroy, nod_: Add Single Directory Components as a new experimental module
2023-04-17 22:07:14 +00:00
// Iterate over all the components to get the CSS and JS files.
$plugin_manager = \Drupal :: service ( 'plugin.manager.sdc' );
assert ( $plugin_manager instanceof ComponentPluginManager );
$components = $plugin_manager -> getAllComponents ();
2024-03-27 21:19:28 +00:00
// Generate backwards compatible deprecated libraries that depend on the new
// library name scheme.
Issue #3340712 by e0ipso, alexpott, larowlan, dww, _pratik_, catch, penyaskito, mherchel, pdureau, jonathanshaw, mglaman, idiaz.roncero, geek-merlin, ctrlADel, mrweiner, bnjmnm, longwave, guschilds, cosmicdreams, dreamleaf, ckrina, Gábor Hojtsy, lauriii, unstatu, markconroy, nod_: Add Single Directory Components as a new experimental module
2023-04-17 22:07:14 +00:00
$libraries = array_reduce (
$components ,
2024-03-27 21:19:28 +00:00
static function ( array $libraries , Component $component ) use ( $deprecation_message ) {
// The library name is something like core/components.my-theme--my-comp.
Issue #3340712 by e0ipso, alexpott, larowlan, dww, _pratik_, catch, penyaskito, mherchel, pdureau, jonathanshaw, mglaman, idiaz.roncero, geek-merlin, ctrlADel, mrweiner, bnjmnm, longwave, guschilds, cosmicdreams, dreamleaf, ckrina, Gábor Hojtsy, lauriii, unstatu, markconroy, nod_: Add Single Directory Components as a new experimental module
2023-04-17 22:07:14 +00:00
$library_name = $component -> getLibraryName ();
2024-03-27 21:19:28 +00:00
// The library ID is something like my-theme--my-comp.
$library_id = str_replace ( 'core/components.' , '' , $library_name );
// Adding these libraries will result in the old 'sdc/my-theme--my-comp'.
return array_merge ( $libraries , [
$library_id => [
'dependencies' => [ $library_name ],
'deprecated' => $deprecation_message ,
],
]);
Issue #3340712 by e0ipso, alexpott, larowlan, dww, _pratik_, catch, penyaskito, mherchel, pdureau, jonathanshaw, mglaman, idiaz.roncero, geek-merlin, ctrlADel, mrweiner, bnjmnm, longwave, guschilds, cosmicdreams, dreamleaf, ckrina, Gábor Hojtsy, lauriii, unstatu, markconroy, nod_: Add Single Directory Components as a new experimental module
2023-04-17 22:07:14 +00:00
},
[]
);
2024-03-27 21:19:28 +00:00
// Alias the library sdc/all to core/components.all.
Issue #3340712 by e0ipso, alexpott, larowlan, dww, _pratik_, catch, penyaskito, mherchel, pdureau, jonathanshaw, mglaman, idiaz.roncero, geek-merlin, ctrlADel, mrweiner, bnjmnm, longwave, guschilds, cosmicdreams, dreamleaf, ckrina, Gábor Hojtsy, lauriii, unstatu, markconroy, nod_: Add Single Directory Components as a new experimental module
2023-04-17 22:07:14 +00:00
$libraries [ 'all' ] = [
2024-03-27 21:19:28 +00:00
'dependencies' => [ 'core/components.all' ],
'deprecated' => 'The %library_id% asset library is deprecated in Drupal 10.3.0 and will be removed in Drupal 11.0.0. Use the core/components.all library instead. See https://www.drupal.org/node/3410260' ,
Issue #3340712 by e0ipso, alexpott, larowlan, dww, _pratik_, catch, penyaskito, mherchel, pdureau, jonathanshaw, mglaman, idiaz.roncero, geek-merlin, ctrlADel, mrweiner, bnjmnm, longwave, guschilds, cosmicdreams, dreamleaf, ckrina, Gábor Hojtsy, lauriii, unstatu, markconroy, nod_: Add Single Directory Components as a new experimental module
2023-04-17 22:07:14 +00:00
];
return $libraries ;
}