1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- use Drupal\Core\Url;
- function edlp_ajax_page_attachments(array &$attachments) {
- $url = Url::fromRoute('edlp_ajax.entityjson');
- $attachments['#attached']['drupalSettings']['edlp_ajax']['entityjson_path'] = $url->getInternalPath();
-
-
- $redirect = false;
- $current_path = \Drupal::service('path.current')->getPath();
- $is_front = \Drupal::service('path.matcher')->isFrontPage();
-
-
- if(preg_match('/^\/?node\/\d+/', $current_path)
- || preg_match('/^\/?taxonomy\/term\/\d+/', $current_path)
- || preg_match('/^\/?productions/', $current_path)
- || preg_match('/^\/?agenda/', $current_path)
- || preg_match('/^\/?studio/', $current_path)
- || preg_match('/^\/?search/', $current_path)){
- $redirect = true;
- }
- $js_str = "var edlp = {\n
- sys_path:'".$current_path."',\n
- is_front:".($is_front ? 'true':'false').",\n
- redirect:".($redirect ? 'true':'false').",\n
- };";
- $attachments['#attached']['html_head'][] = [
- [
- '#type' => 'html_tag',
- '#tag' => 'script',
- '#value' => $js_str,
- '#weight' => -999,
- '#group' => 'edlp'
- ],
-
- 'edlp',
- ];
- }
- function edlp_ajax_theme($existing, $type, $theme, $path) {
-
- return array(
- 'edlp_ajax' => array(
- 'file' => 'includes/edlp_ajax.inc',
- 'variables' => array(
- 'entity_type' => 'node',
- 'entity' => NULL,
- 'view_mode' => 'default'
- ),
- ),
- );
- }
- function edlp_ajax_theme_suggestions_edlp_ajax(array $vars) {
-
- $suggestions = [];
-
- $sanitized_view_mode = strtr($vars['view_mode'], '.', '_');
-
- $suggestions[] = 'edlp_ajax__' . $vars['entity_type'];
- $suggestions[] = 'edlp_ajax__' . $vars['entity_type'] . '__' . $sanitized_view_mode;
-
- $suggestions[] = 'edlp_ajax__' . $vars['entity_type'] . '__' . $vars['entity']->id();
- $suggestions[] = 'edlp_ajax__' . $vars['entity_type'] . '__' . $vars['entity']->id() . '__' . $sanitized_view_mode;
- return $suggestions;
- }
|