public static Views::getApplicableViews($type)
Return a list of all view IDs and display IDs that have a particular setting in their display's plugin settings.
1 2 3 4 | array ( array ( $view_id , $display_id ), array ( $view_id , $display_id ), ); |
Parameters
string $type: A flag from the display plugin definitions (e.g, 'uses_menu_links').
Return value
array A list of arrays containing the $view_id and $display_id.
File
- core/modules/views/src/Views.php, line 205
Class
- Views
- Static service container wrapper for views.
Namespace
Drupal\views
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | public static function getApplicableViews( $type ) { // Get all display plugins which provides the type. $display_plugins = static ::pluginManager( 'display' )->getDefinitions(); $plugin_ids = []; foreach ( $display_plugins as $id => $definition ) { if (! empty ( $definition [ $type ])) { $plugin_ids [ $id ] = $id ; } } $entity_ids = \Drupal::service( 'entity.query' )->get( 'view' ) ->condition( 'status' , TRUE) ->condition( "display.*.display_plugin" , $plugin_ids , 'IN' ) ->execute(); $result = array (); foreach (\Drupal::entityManager()->getStorage( 'view' )->loadMultiple( $entity_ids ) as $view ) { // Check each display to see if it meets the criteria and is enabled. foreach ( $view ->get( 'display' ) as $id => $display ) { // If the key doesn't exist, enabled is assumed. $enabled = ! empty ( $display [ 'display_options' ][ 'enabled' ]) || ! array_key_exists ( 'enabled' , $display [ 'display_options' ]); if ( $enabled && in_array( $display [ 'display_plugin' ], $plugin_ids )) { $result [] = [ $view ->id(), $id ]; } } } return $result ; } |
Please login to continue.