Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / front / front_page.module
1 <?php
2
3 /**
4  * @file
5  * This module allows the site admin to set advanced front page settings.
6  *
7  * This version is for Drupal 8.
8  * Earlier versions can be found at http://drupal.org/project/front.
9  *
10  * This module version was developed by timhilliard and various members
11  * of the drupal community.
12  *
13  * If you have any ideas/patches or requests,
14  * please post them at http://drupal.org/project/issues/front.
15  */
16
17 use Drupal\Core\Database\Database;
18 use Drupal\Core\Render\Element;
19 use \Drupal\Core\Link;
20 use \Drupal\Core\Url;
21
22 /**
23  * Implements hook_help().
24  */
25 function front_page_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) {
26   switch ($route_name) {
27     case 'front_page.settings':
28       return t('<p>Setup custom front pages for your site.</p>');
29
30     case 'front_page.home_links':
31       return t('<p>If a HOME link is set, the &lt;front&gt; placeholder will be replaced with this value instead of the standard front page.</p>');
32   }
33 }
34
35 /**
36  * Function to parse a full URL including GET variables and fragment
37  * to an array ready for drupal_goto(), url(), or l() functions.
38  */
39 function front_page_parse_url($path) {
40   $url['path'] = $path;
41   $url['options'] = array();
42   if (preg_match('@^(?P<path>[^?#]+)(\?(?P<query>[^#]*))?(#(?P<fragment>.*))?$@', $path, $match)) {
43     $url['path'] = $match['path'];
44     if (!empty($match['query'])) {
45       foreach (explode('&', $match['query']) as $query_part) {
46         list($key, $value) = explode('=', $query_part);
47         $url['options']['query'][$key] = $value;
48       }
49     }
50     if (!empty($match['fragment'])) {
51       $url['options']['fragment'] = $match['fragment'];
52     }
53   }
54   return $url;
55 }
56
57 /**
58  * Function to return the first role enabled in front page, ordered by weight.
59  */
60 function front_page_get_by_role($index = 0, $number = 1) {
61   $roles = \Drupal::currentUser()->getRoles();
62   $result = Database::getConnection()->select('front_page', 'fp')
63     ->fields('fp')
64     ->condition('rid', $roles, 'IN')
65     ->condition('mode', '', '<>')
66     ->orderBy('weight', 'ASC')
67     ->orderBy('rid', 'DESC')
68     ->range($index, $number)
69     ->execute()
70     ->fetchAssoc();
71   return $result;
72 }
73
74 /**
75  * Function to return the first role enabled in front page, ordered by weight.
76  */
77 function front_page_get_by_rid($rid) {
78
79   $result = Database::getConnection()->select('front_page', 'fp')
80     ->fields('fp')
81     ->condition('rid', $rid)
82     ->condition('mode', '', '<>')
83     ->execute()
84     ->fetchAssoc();
85   return $result;
86 }
87
88 /**
89  * Function to return all the roles in front page, ordered by weight.
90  */
91 function front_page_get_all() {
92   $result = Database::getConnection()->select('front_page', 'fp')
93     ->fields('fp')
94     ->orderBy('weight', 'ASC')
95     ->orderBy('rid', 'DESC')
96     ->execute()
97     ->fetchAllAssoc('rid', PDO::FETCH_ASSOC);
98   return $result;
99 }
100
101 /**
102  * Implements hook_theme().
103  */
104 function front_page_theme() {
105   return array(
106     'front_page_admin_arrange_form' => array(
107       'render element' => 'form',
108       'function' => 'theme_front_page_admin_arrange_form',
109     ),
110   );
111 }
112
113 /**
114  * Implements hook_user_role_delete().
115  */
116 function front_page_user_role_delete($role) {
117   // Delete Front configuration for the role being deleted.
118   Database::getConnection()->delete('front_page')
119     ->condition('rid', $role->rid)
120     ->execute();
121 }
122
123 /**
124  * Returns HTML for the front page arrange form into a table.
125  *
126  * @param array $variables
127  *   An associative array containing:
128  *   - form: A render element representing the form.
129  */
130 function theme_front_page_admin_arrange_form($variables) {
131   $form = $variables['form'];
132
133   // Enable the drag handles.
134   drupal_attach_tabledrag($form['roles'], array(
135     'table_id' => 'front-page-arrange',
136     'action' => 'order',
137     'relationship' => 'sibling',
138     'group' => 'front-page-weight',
139   ));
140
141   $header = array(
142     t('Role'),
143     t('Mode'),
144     t('Preview'),
145     t('Enabled'),
146     t('Weight'),
147   );
148
149   $rows = array();
150   $renderer = \Drupal::service('renderer');
151   foreach (Element::children($form['roles']) as $rid) {
152     $element = &$form['roles'][$rid];
153
154     // Add special classes to be used for tabledrag.js.
155     $element['weight']['#attributes']['class'] = array('front-page-weight');
156
157     $row = array();
158     $row[] = $renderer->render($element['title'], FALSE);
159     $row[] = $renderer->render($element['mode'], FALSE);
160     $row[] = $renderer->render($element['preview'], FALSE);
161     $row[] = $renderer->render($element['enabled'], FALSE);
162     $row[] = $renderer->render($element['weight'], FALSE);
163
164     $row = array_merge(array('data' => $row), $element['#attributes']);
165     $row['class'][] = 'draggable';
166     $rows[] = $row;
167   }
168   $output = '';
169   if (empty($rows)) {
170     $rows[] = array(array('data' => 'no roles', 'colspan' => '5'));
171   }
172
173   $front_page_arrange = [
174     '#theme' => 'table',
175     '#header' => $header,
176     '#rows' => $rows,
177     'attributes' => array('id' => 'front-page-arrange'),
178   ];
179   $output .= $renderer->render($front_page_arrange);
180   $output .= drupal_render_children($form);
181   return $output;
182 }