theme.inc 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867
  1. <?php
  2. /**
  3. * @file
  4. * The theme system, which controls the output of Drupal.
  5. *
  6. * The theme system allows for nearly all output of the Drupal system to be
  7. * customized by user themes.
  8. */
  9. use Drupal\Component\Serialization\Json;
  10. use Drupal\Component\Utility\Crypt;
  11. use Drupal\Component\Utility\Html;
  12. use Drupal\Component\Render\MarkupInterface;
  13. use Drupal\Component\Utility\Unicode;
  14. use Drupal\Core\Cache\CacheableDependencyInterface;
  15. use Drupal\Core\Config\Config;
  16. use Drupal\Core\Config\StorageException;
  17. use Drupal\Core\Render\AttachmentsInterface;
  18. use Drupal\Core\Render\BubbleableMetadata;
  19. use Drupal\Core\Render\RenderableInterface;
  20. use Drupal\Core\Template\Attribute;
  21. use Drupal\Core\Theme\ThemeSettings;
  22. use Drupal\Component\Utility\NestedArray;
  23. use Drupal\Core\Render\Element;
  24. use Drupal\Core\Render\Markup;
  25. /**
  26. * @defgroup content_flags Content markers
  27. * @{
  28. * Markers used by mark.html.twig and node_mark() to designate content.
  29. *
  30. * @see mark.html.twig
  31. * @see node_mark()
  32. */
  33. /**
  34. * Mark content as read.
  35. */
  36. const MARK_READ = 0;
  37. /**
  38. * Mark content as being new.
  39. */
  40. const MARK_NEW = 1;
  41. /**
  42. * Mark content as being updated.
  43. */
  44. const MARK_UPDATED = 2;
  45. /**
  46. * A responsive table class; hide table cell on narrow devices.
  47. *
  48. * Indicates that a column has medium priority and thus can be hidden on narrow
  49. * width devices and shown on medium+ width devices (i.e. tablets and desktops).
  50. */
  51. const RESPONSIVE_PRIORITY_MEDIUM = 'priority-medium';
  52. /**
  53. * A responsive table class; only show table cell on wide devices.
  54. *
  55. * Indicates that a column has low priority and thus can be hidden on narrow
  56. * and medium viewports and shown on wide devices (i.e. desktops).
  57. */
  58. const RESPONSIVE_PRIORITY_LOW = 'priority-low';
  59. /**
  60. * @} End of "defgroup content_flags".
  61. */
  62. /**
  63. * Gets the theme registry.
  64. *
  65. * @param bool $complete
  66. * Optional boolean to indicate whether to return the complete theme registry
  67. * array or an instance of the Drupal\Core\Utility\ThemeRegistry class.
  68. * If TRUE, the complete theme registry array will be returned. This is useful
  69. * if you want to foreach over the whole registry, use array_* functions or
  70. * inspect it in a debugger. If FALSE, an instance of the
  71. * Drupal\Core\Utility\ThemeRegistry class will be returned, this provides an
  72. * ArrayObject which allows it to be accessed with array syntax and isset(),
  73. * and should be more lightweight than the full registry. Defaults to TRUE.
  74. *
  75. * @return
  76. * The complete theme registry array, or an instance of the
  77. * Drupal\Core\Utility\ThemeRegistry class.
  78. */
  79. function theme_get_registry($complete = TRUE) {
  80. $theme_registry = \Drupal::service('theme.registry');
  81. if ($complete) {
  82. return $theme_registry->get();
  83. }
  84. else {
  85. return $theme_registry->getRuntime();
  86. }
  87. }
  88. /**
  89. * Returns an array of default theme features.
  90. *
  91. * @see \Drupal\Core\Extension\ThemeHandler::$defaultFeatures
  92. */
  93. function _system_default_theme_features() {
  94. return [
  95. 'favicon',
  96. 'logo',
  97. 'node_user_picture',
  98. 'comment_user_picture',
  99. 'comment_user_verification',
  100. ];
  101. }
  102. /**
  103. * Forces the system to rebuild the theme registry.
  104. *
  105. * This function should be called when modules are added to the system, or when
  106. * a dynamic system needs to add more theme hooks.
  107. */
  108. function drupal_theme_rebuild() {
  109. \Drupal::service('theme.registry')->reset();
  110. }
  111. /**
  112. * Allows themes and/or theme engines to discover overridden theme functions.
  113. *
  114. * @param array $cache
  115. * The existing cache of theme hooks to test against.
  116. * @param array $prefixes
  117. * An array of prefixes to test, in reverse order of importance.
  118. *
  119. * @return array
  120. * The functions found, suitable for returning from hook_theme;
  121. */
  122. function drupal_find_theme_functions($cache, $prefixes) {
  123. $implementations = [];
  124. $grouped_functions = \Drupal::service('theme.registry')->getPrefixGroupedUserFunctions($prefixes);
  125. foreach ($cache as $hook => $info) {
  126. foreach ($prefixes as $prefix) {
  127. // Find theme functions that implement possible "suggestion" variants of
  128. // registered theme hooks and add those as new registered theme hooks.
  129. // The 'pattern' key defines a common prefix that all suggestions must
  130. // start with. The default is the name of the hook followed by '__'. An
  131. // 'base hook' key is added to each entry made for a found suggestion,
  132. // so that common functionality can be implemented for all suggestions of
  133. // the same base hook. To keep things simple, deep hierarchy of
  134. // suggestions is not supported: each suggestion's 'base hook' key
  135. // refers to a base hook, not to another suggestion, and all suggestions
  136. // are found using the base hook's pattern, not a pattern from an
  137. // intermediary suggestion.
  138. $pattern = isset($info['pattern']) ? $info['pattern'] : ($hook . '__');
  139. // Grep only the functions which are within the prefix group.
  140. list($first_prefix,) = explode('_', $prefix, 2);
  141. if (!isset($info['base hook']) && !empty($pattern) && isset($grouped_functions[$first_prefix])) {
  142. $matches = preg_grep('/^' . $prefix . '_' . $pattern . '/', $grouped_functions[$first_prefix]);
  143. if ($matches) {
  144. foreach ($matches as $match) {
  145. $new_hook = substr($match, strlen($prefix) + 1);
  146. $arg_name = isset($info['variables']) ? 'variables' : 'render element';
  147. $implementations[$new_hook] = [
  148. 'function' => $match,
  149. $arg_name => $info[$arg_name],
  150. 'base hook' => $hook,
  151. ];
  152. }
  153. }
  154. }
  155. // Find theme functions that implement registered theme hooks and include
  156. // that in what is returned so that the registry knows that the theme has
  157. // this implementation.
  158. if (function_exists($prefix . '_' . $hook)) {
  159. $implementations[$hook] = [
  160. 'function' => $prefix . '_' . $hook,
  161. ];
  162. }
  163. }
  164. }
  165. return $implementations;
  166. }
  167. /**
  168. * Allows themes and/or theme engines to easily discover overridden templates.
  169. *
  170. * @param $cache
  171. * The existing cache of theme hooks to test against.
  172. * @param $extension
  173. * The extension that these templates will have.
  174. * @param $path
  175. * The path to search.
  176. */
  177. function drupal_find_theme_templates($cache, $extension, $path) {
  178. $implementations = [];
  179. // Collect paths to all sub-themes grouped by base themes. These will be
  180. // used for filtering. This allows base themes to have sub-themes in its
  181. // folder hierarchy without affecting the base themes template discovery.
  182. $theme_paths = [];
  183. foreach (\Drupal::service('theme_handler')->listInfo() as $theme_info) {
  184. if (!empty($theme_info->base_theme)) {
  185. $theme_paths[$theme_info->base_theme][$theme_info->getName()] = $theme_info->getPath();
  186. }
  187. }
  188. foreach ($theme_paths as $basetheme => $subthemes) {
  189. foreach ($subthemes as $subtheme => $subtheme_path) {
  190. if (isset($theme_paths[$subtheme])) {
  191. $theme_paths[$basetheme] = array_merge($theme_paths[$basetheme], $theme_paths[$subtheme]);
  192. }
  193. }
  194. }
  195. $theme = \Drupal::theme()->getActiveTheme()->getName();
  196. $subtheme_paths = isset($theme_paths[$theme]) ? $theme_paths[$theme] : [];
  197. // Escape the periods in the extension.
  198. $regex = '/' . str_replace('.', '\.', $extension) . '$/';
  199. // Get a listing of all template files in the path to search.
  200. $files = file_scan_directory($path, $regex, ['key' => 'filename']);
  201. // Find templates that implement registered theme hooks and include that in
  202. // what is returned so that the registry knows that the theme has this
  203. // implementation.
  204. foreach ($files as $template => $file) {
  205. // Ignore sub-theme templates for the current theme.
  206. if (strpos($file->uri, str_replace($subtheme_paths, '', $file->uri)) !== 0) {
  207. continue;
  208. }
  209. // Remove the extension from the filename.
  210. $template = str_replace($extension, '', $template);
  211. // Transform - in filenames to _ to match function naming scheme
  212. // for the purposes of searching.
  213. $hook = strtr($template, '-', '_');
  214. if (isset($cache[$hook])) {
  215. $implementations[$hook] = [
  216. 'template' => $template,
  217. 'path' => dirname($file->uri),
  218. ];
  219. }
  220. // Match templates based on the 'template' filename.
  221. foreach ($cache as $hook => $info) {
  222. if (isset($info['template'])) {
  223. if ($template === $info['template']) {
  224. $implementations[$hook] = [
  225. 'template' => $template,
  226. 'path' => dirname($file->uri),
  227. ];
  228. }
  229. }
  230. }
  231. }
  232. // Find templates that implement possible "suggestion" variants of registered
  233. // theme hooks and add those as new registered theme hooks. See
  234. // drupal_find_theme_functions() for more information about suggestions and
  235. // the use of 'pattern' and 'base hook'.
  236. $patterns = array_keys($files);
  237. foreach ($cache as $hook => $info) {
  238. $pattern = isset($info['pattern']) ? $info['pattern'] : ($hook . '__');
  239. if (!isset($info['base hook']) && !empty($pattern)) {
  240. // Transform _ in pattern to - to match file naming scheme
  241. // for the purposes of searching.
  242. $pattern = strtr($pattern, '_', '-');
  243. $matches = preg_grep('/^' . $pattern . '/', $patterns);
  244. if ($matches) {
  245. foreach ($matches as $match) {
  246. $file = $match;
  247. // Remove the extension from the filename.
  248. $file = str_replace($extension, '', $file);
  249. // Put the underscores back in for the hook name and register this
  250. // pattern.
  251. $arg_name = isset($info['variables']) ? 'variables' : 'render element';
  252. $implementations[strtr($file, '-', '_')] = [
  253. 'template' => $file,
  254. 'path' => dirname($files[$match]->uri),
  255. $arg_name => $info[$arg_name],
  256. 'base hook' => $hook,
  257. ];
  258. }
  259. }
  260. }
  261. }
  262. return $implementations;
  263. }
  264. /**
  265. * Retrieves a setting for the current theme or for a given theme.
  266. *
  267. * The final setting is obtained from the last value found in the following
  268. * sources:
  269. * - the saved values from the global theme settings form
  270. * - the saved values from the theme's settings form
  271. * To only retrieve the default global theme setting, an empty string should be
  272. * given for $theme.
  273. *
  274. * @param $setting_name
  275. * The name of the setting to be retrieved.
  276. * @param $theme
  277. * The name of a given theme; defaults to the current theme.
  278. *
  279. * @return
  280. * The value of the requested setting, NULL if the setting does not exist.
  281. */
  282. function theme_get_setting($setting_name, $theme = NULL) {
  283. /** @var \Drupal\Core\Theme\ThemeSettings[] $cache */
  284. $cache = &drupal_static(__FUNCTION__, []);
  285. // If no key is given, use the current theme if we can determine it.
  286. if (!isset($theme)) {
  287. $theme = \Drupal::theme()->getActiveTheme()->getName();
  288. }
  289. if (empty($cache[$theme])) {
  290. // Create a theme settings object.
  291. $cache[$theme] = new ThemeSettings($theme);
  292. // Get the global settings from configuration.
  293. $cache[$theme]->setData(\Drupal::config('system.theme.global')->get());
  294. // Get the values for the theme-specific settings from the .info.yml files
  295. // of the theme and all its base themes.
  296. $themes = \Drupal::service('theme_handler')->listInfo();
  297. if (isset($themes[$theme])) {
  298. $theme_object = $themes[$theme];
  299. // Retrieve configured theme-specific settings, if any.
  300. try {
  301. if ($theme_settings = \Drupal::config($theme . '.settings')->get()) {
  302. $cache[$theme]->merge($theme_settings);
  303. }
  304. }
  305. catch (StorageException $e) {
  306. }
  307. // If the theme does not support a particular feature, override the global
  308. // setting and set the value to NULL.
  309. if (!empty($theme_object->info['features'])) {
  310. foreach (_system_default_theme_features() as $feature) {
  311. if (!in_array($feature, $theme_object->info['features'])) {
  312. $cache[$theme]->set('features.' . $feature, NULL);
  313. }
  314. }
  315. }
  316. // Generate the path to the logo image.
  317. if ($cache[$theme]->get('logo.use_default')) {
  318. $cache[$theme]->set('logo.url', file_url_transform_relative(file_create_url($theme_object->getPath() . '/logo.svg')));
  319. }
  320. elseif ($logo_path = $cache[$theme]->get('logo.path')) {
  321. $cache[$theme]->set('logo.url', file_url_transform_relative(file_create_url($logo_path)));
  322. }
  323. // Generate the path to the favicon.
  324. if ($cache[$theme]->get('features.favicon')) {
  325. $favicon_path = $cache[$theme]->get('favicon.path');
  326. if ($cache[$theme]->get('favicon.use_default')) {
  327. if (file_exists($favicon = $theme_object->getPath() . '/favicon.ico')) {
  328. $cache[$theme]->set('favicon.url', file_url_transform_relative(file_create_url($favicon)));
  329. }
  330. else {
  331. $cache[$theme]->set('favicon.url', file_url_transform_relative(file_create_url('core/misc/favicon.ico')));
  332. }
  333. }
  334. elseif ($favicon_path) {
  335. $cache[$theme]->set('favicon.url', file_url_transform_relative(file_create_url($favicon_path)));
  336. }
  337. else {
  338. $cache[$theme]->set('features.favicon', FALSE);
  339. }
  340. }
  341. }
  342. }
  343. return $cache[$theme]->get($setting_name);
  344. }
  345. /**
  346. * Escapes and renders variables for theme functions.
  347. *
  348. * This method is used in theme functions to ensure that the result is safe for
  349. * output inside HTML fragments. This mimics the behavior of the auto-escape
  350. * functionality in Twig.
  351. *
  352. * Note: This function should be kept in sync with
  353. * \Drupal\Core\Template\TwigExtension::escapeFilter().
  354. *
  355. * @param mixed $arg
  356. * The string, object, or render array to escape if needed.
  357. *
  358. * @return string
  359. * The rendered string, safe for use in HTML. The string is not safe when used
  360. * as any part of an HTML attribute name or value.
  361. *
  362. * @throws \Exception
  363. * Thrown when an object is passed in which cannot be printed.
  364. *
  365. * @see \Drupal\Core\Template\TwigExtension::escapeFilter()
  366. *
  367. * @todo Discuss deprecating this in https://www.drupal.org/node/2575081.
  368. * @todo Refactor this to keep it in sync with Twig filtering in
  369. * https://www.drupal.org/node/2575065
  370. */
  371. function theme_render_and_autoescape($arg) {
  372. // If it's a renderable, then it'll be up to the generated render array it
  373. // returns to contain the necessary cacheability & attachment metadata. If
  374. // it doesn't implement CacheableDependencyInterface or AttachmentsInterface
  375. // then there is nothing to do here.
  376. if (!($arg instanceof RenderableInterface) && ($arg instanceof CacheableDependencyInterface || $arg instanceof AttachmentsInterface)) {
  377. $arg_bubbleable = [];
  378. BubbleableMetadata::createFromObject($arg)
  379. ->applyTo($arg_bubbleable);
  380. \Drupal::service('renderer')->render($arg_bubbleable);
  381. }
  382. if ($arg instanceof MarkupInterface) {
  383. return (string) $arg;
  384. }
  385. $return = NULL;
  386. if (is_scalar($arg)) {
  387. $return = (string) $arg;
  388. }
  389. elseif (is_object($arg)) {
  390. if ($arg instanceof RenderableInterface) {
  391. $arg = $arg->toRenderable();
  392. }
  393. elseif (method_exists($arg, '__toString')) {
  394. $return = (string) $arg;
  395. }
  396. // You can't throw exceptions in the magic PHP __toString methods, see
  397. // http://php.net/manual/language.oop5.magic.php#object.tostring so
  398. // we also support a toString method.
  399. elseif (method_exists($arg, 'toString')) {
  400. $return = $arg->toString();
  401. }
  402. else {
  403. throw new \Exception('Object of type ' . get_class($arg) . ' cannot be printed.');
  404. }
  405. }
  406. // We have a string or an object converted to a string: Escape it!
  407. if (isset($return)) {
  408. return $return instanceof MarkupInterface ? $return : Html::escape($return);
  409. }
  410. // This is a normal render array, which is safe by definition, with special
  411. // simple cases already handled.
  412. // Early return if this element was pre-rendered (no need to re-render).
  413. if (isset($arg['#printed']) && $arg['#printed'] == TRUE && isset($arg['#markup']) && strlen($arg['#markup']) > 0) {
  414. return (string) $arg['#markup'];
  415. }
  416. $arg['#printed'] = FALSE;
  417. return (string) \Drupal::service('renderer')->render($arg);
  418. }
  419. /**
  420. * Converts theme settings to configuration.
  421. *
  422. * @see system_theme_settings_submit()
  423. *
  424. * @param array $theme_settings
  425. * An array of theme settings from system setting form or a Drupal 7 variable.
  426. * @param \Drupal\Core\Config\Config $config
  427. * The configuration object to update.
  428. *
  429. * @return
  430. * The Config object with updated data.
  431. */
  432. function theme_settings_convert_to_config(array $theme_settings, Config $config) {
  433. foreach ($theme_settings as $key => $value) {
  434. if ($key == 'default_logo') {
  435. $config->set('logo.use_default', $value);
  436. }
  437. elseif ($key == 'logo_path') {
  438. $config->set('logo.path', $value);
  439. }
  440. elseif ($key == 'default_favicon') {
  441. $config->set('favicon.use_default', $value);
  442. }
  443. elseif ($key == 'favicon_path') {
  444. $config->set('favicon.path', $value);
  445. }
  446. elseif ($key == 'favicon_mimetype') {
  447. $config->set('favicon.mimetype', $value);
  448. }
  449. elseif (substr($key, 0, 7) == 'toggle_') {
  450. $config->set('features.' . Unicode::substr($key, 7), $value);
  451. }
  452. elseif (!in_array($key, ['theme', 'logo_upload'])) {
  453. $config->set($key, $value);
  454. }
  455. }
  456. return $config;
  457. }
  458. /**
  459. * Prepares variables for time templates.
  460. *
  461. * Default template: time.html.twig.
  462. *
  463. * @param array $variables
  464. * An associative array possibly containing:
  465. * - attributes['timestamp']:
  466. * - timestamp:
  467. * - text:
  468. */
  469. function template_preprocess_time(&$variables) {
  470. // Format the 'datetime' attribute based on the timestamp.
  471. // @see http://www.w3.org/TR/html5-author/the-time-element.html#attr-time-datetime
  472. if (!isset($variables['attributes']['datetime']) && isset($variables['timestamp'])) {
  473. $variables['attributes']['datetime'] = format_date($variables['timestamp'], 'html_datetime', '', 'UTC');
  474. }
  475. // If no text was provided, try to auto-generate it.
  476. if (!isset($variables['text'])) {
  477. // Format and use a human-readable version of the timestamp, if any.
  478. if (isset($variables['timestamp'])) {
  479. $variables['text'] = format_date($variables['timestamp']);
  480. }
  481. // Otherwise, use the literal datetime attribute.
  482. elseif (isset($variables['attributes']['datetime'])) {
  483. $variables['text'] = $variables['attributes']['datetime'];
  484. }
  485. }
  486. }
  487. /**
  488. * Prepares variables for datetime form element templates.
  489. *
  490. * The datetime form element serves as a wrapper around the date element type,
  491. * which creates a date and a time component for a date.
  492. *
  493. * Default template: datetime-form.html.twig.
  494. *
  495. * @param array $variables
  496. * An associative array containing:
  497. * - element: An associative array containing the properties of the element.
  498. * Properties used: #title, #value, #options, #description, #required,
  499. * #attributes.
  500. *
  501. * @see form_process_datetime()
  502. */
  503. function template_preprocess_datetime_form(&$variables) {
  504. $element = $variables['element'];
  505. $variables['attributes'] = [];
  506. if (isset($element['#id'])) {
  507. $variables['attributes']['id'] = $element['#id'];
  508. }
  509. if (!empty($element['#attributes']['class'])) {
  510. $variables['attributes']['class'] = (array) $element['#attributes']['class'];
  511. }
  512. $variables['content'] = $element;
  513. }
  514. /**
  515. * Prepares variables for datetime form wrapper templates.
  516. *
  517. * Default template: datetime-wrapper.html.twig.
  518. *
  519. * @param array $variables
  520. * An associative array containing:
  521. * - element: An associative array containing the properties of the element.
  522. * Properties used: #title, #children, #required, #attributes.
  523. */
  524. function template_preprocess_datetime_wrapper(&$variables) {
  525. $element = $variables['element'];
  526. if (!empty($element['#title'])) {
  527. $variables['title'] = $element['#title'];
  528. }
  529. // Suppress error messages.
  530. $variables['errors'] = NULL;
  531. $variables['description'] = NULL;
  532. if (!empty($element['#description'])) {
  533. $description_attributes = [];
  534. if (!empty($element['#id'])) {
  535. $description_attributes['id'] = $element['#id'] . '--description';
  536. }
  537. $variables['description'] = $element['#description'];
  538. $variables['description_attributes'] = new Attribute($description_attributes);
  539. }
  540. $variables['required'] = FALSE;
  541. // For required datetime fields 'form-required' & 'js-form-required' classes
  542. // are appended to the label attributes.
  543. if (!empty($element['#required'])) {
  544. $variables['required'] = TRUE;
  545. }
  546. $variables['content'] = $element['#children'];
  547. }
  548. /**
  549. * Prepares variables for links templates.
  550. *
  551. * Default template: links.html.twig.
  552. *
  553. * Unfortunately links templates duplicate the "active" class handling of l()
  554. * and LinkGenerator::generate() because it needs to be able to set the "active"
  555. * class not on the links themselves (<a> tags), but on the list items (<li>
  556. * tags) that contain the links. This is necessary for CSS to be able to style
  557. * list items differently when the link is active, since CSS does not yet allow
  558. * one to style list items only if it contains a certain element with a certain
  559. * class. I.e. we cannot yet convert this jQuery selector to a CSS selector:
  560. * jQuery('li:has("a.is-active")')
  561. *
  562. * @param array $variables
  563. * An associative array containing:
  564. * - links: An array of links to be themed. Each link should be itself an
  565. * array, with the following elements:
  566. * - title: The link text.
  567. * - url: (optional) The \Drupal\Core\Url object to link to. If omitted, no
  568. * anchor tag is printed out.
  569. * - attributes: (optional) Attributes for the anchor, or for the <span>
  570. * tag used in its place if no 'href' is supplied. If element 'class' is
  571. * included, it must be an array of one or more class names.
  572. * If the 'href' element is supplied, the entire link array is passed to
  573. * l() as its $options parameter.
  574. * - attributes: A keyed array of attributes for the <ul> containing the list
  575. * of links.
  576. * - set_active_class: (optional) Whether each link should compare the
  577. * route_name + route_parameters or href (path), language and query options
  578. * to the current URL, to determine whether the link is "active". If so, an
  579. * "active" class will be applied to the list item containing the link, as
  580. * well as the link itself. It is important to use this sparingly since it
  581. * is usually unnecessary and requires extra processing.
  582. * For anonymous users, the "active" class will be calculated on the server,
  583. * because most sites serve each anonymous user the same cached page anyway.
  584. * For authenticated users, the "active" class will be calculated on the
  585. * client (through JavaScript), only data- attributes are added to list
  586. * items and contained links, to prevent breaking the render cache. The
  587. * JavaScript is added in system_page_attachments().
  588. * - heading: (optional) A heading to precede the links. May be an
  589. * associative array or a string. If it's an array, it can have the
  590. * following elements:
  591. * - text: The heading text.
  592. * - level: The heading level (e.g. 'h2', 'h3').
  593. * - attributes: (optional) An array of the CSS attributes for the heading.
  594. * When using a string it will be used as the text of the heading and the
  595. * level will default to 'h2'. Headings should be used on navigation menus
  596. * and any list of links that consistently appears on multiple pages. To
  597. * make the heading invisible use the 'visually-hidden' CSS class. Do not
  598. * use 'display:none', which removes it from screen readers and assistive
  599. * technology. Headings allow screen reader and keyboard only users to
  600. * navigate to or skip the links. See
  601. * http://juicystudio.com/article/screen-readers-display-none.php and
  602. * http://www.w3.org/TR/WCAG-TECHS/H42.html for more information.
  603. *
  604. * @see \Drupal\Core\Utility\LinkGenerator
  605. * @see \Drupal\Core\Utility\LinkGenerator::generate()
  606. * @see system_page_attachments()
  607. */
  608. function template_preprocess_links(&$variables) {
  609. $links = $variables['links'];
  610. $heading = &$variables['heading'];
  611. if (!empty($links)) {
  612. // Prepend the heading to the list, if any.
  613. if (!empty($heading)) {
  614. // Convert a string heading into an array, using a <h2> tag by default.
  615. if (is_string($heading)) {
  616. $heading = ['text' => $heading];
  617. }
  618. // Merge in default array properties into $heading.
  619. $heading += [
  620. 'level' => 'h2',
  621. 'attributes' => [],
  622. ];
  623. // Convert the attributes array into an Attribute object.
  624. $heading['attributes'] = new Attribute($heading['attributes']);
  625. }
  626. $variables['links'] = [];
  627. foreach ($links as $key => $link) {
  628. $item = [];
  629. $link += [
  630. 'ajax' => NULL,
  631. 'url' => NULL,
  632. ];
  633. $li_attributes = [];
  634. $keys = ['title', 'url'];
  635. $link_element = [
  636. '#type' => 'link',
  637. '#title' => $link['title'],
  638. '#options' => array_diff_key($link, array_combine($keys, $keys)),
  639. '#url' => $link['url'],
  640. '#ajax' => $link['ajax'],
  641. ];
  642. // Handle links and ensure that the active class is added on the LIs, but
  643. // only if the 'set_active_class' option is not empty.
  644. if (isset($link['url'])) {
  645. if (!empty($variables['set_active_class'])) {
  646. // Also enable set_active_class for the contained link.
  647. $link_element['#options']['set_active_class'] = TRUE;
  648. if (!empty($link['language'])) {
  649. $li_attributes['hreflang'] = $link['language']->getId();
  650. }
  651. // Add a "data-drupal-link-query" attribute to let the
  652. // drupal.active-link library know the query in a standardized manner.
  653. if (!empty($link['query'])) {
  654. $query = $link['query'];
  655. ksort($query);
  656. $li_attributes['data-drupal-link-query'] = Json::encode($query);
  657. }
  658. /** @var \Drupal\Core\Url $url */
  659. $url = $link['url'];
  660. if ($url->isRouted()) {
  661. // Add a "data-drupal-link-system-path" attribute to let the
  662. // drupal.active-link library know the path in a standardized manner.
  663. $system_path = $url->getInternalPath();
  664. // @todo System path is deprecated - use the route name and parameters.
  665. // Special case for the front page.
  666. $li_attributes['data-drupal-link-system-path'] = $system_path == '' ? '<front>' : $system_path;
  667. }
  668. }
  669. $item['link'] = $link_element;
  670. }
  671. // Handle title-only text items.
  672. $item['text'] = $link['title'];
  673. if (isset($link['attributes'])) {
  674. $item['text_attributes'] = new Attribute($link['attributes']);
  675. }
  676. // Handle list item attributes.
  677. $item['attributes'] = new Attribute($li_attributes);
  678. // Add the item to the list of links.
  679. $variables['links'][$key] = $item;
  680. }
  681. }
  682. }
  683. /**
  684. * Prepares variables for image templates.
  685. *
  686. * Default template: image.html.twig.
  687. *
  688. * @param array $variables
  689. * An associative array containing:
  690. * - uri: Either the path of the image file (relative to base_path()) or a
  691. * full URL.
  692. * - width: The width of the image (if known).
  693. * - height: The height of the image (if known).
  694. * - alt: The alternative text for text-based browsers. HTML 4 and XHTML 1.0
  695. * always require an alt attribute. The HTML 5 draft allows the alt
  696. * attribute to be omitted in some cases. Therefore, this variable defaults
  697. * to an empty string, but can be set to NULL for the attribute to be
  698. * omitted. Usually, neither omission nor an empty string satisfies
  699. * accessibility requirements, so it is strongly encouraged for code
  700. * building variables for image.html.twig templates to pass a meaningful
  701. * value for this variable.
  702. * - http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.8
  703. * - http://www.w3.org/TR/xhtml1/dtds.html
  704. * - http://dev.w3.org/html5/spec/Overview.html#alt
  705. * - title: The title text is displayed when the image is hovered in some
  706. * popular browsers.
  707. * - attributes: Associative array of attributes to be placed in the img tag.
  708. * - srcset: Array of multiple URIs and sizes/multipliers.
  709. * - sizes: The sizes attribute for viewport-based selection of images.
  710. * - http://www.whatwg.org/specs/web-apps/current-work/multipage/embedded-content.html#introduction-3:viewport-based-selection-2
  711. */
  712. function template_preprocess_image(&$variables) {
  713. if (!empty($variables['uri'])) {
  714. $variables['attributes']['src'] = file_url_transform_relative(file_create_url($variables['uri']));
  715. }
  716. // Generate a srcset attribute conforming to the spec at
  717. // http://www.w3.org/html/wg/drafts/html/master/embedded-content.html#attr-img-srcset
  718. if (!empty($variables['srcset'])) {
  719. $srcset = [];
  720. foreach ($variables['srcset'] as $src) {
  721. // URI is mandatory.
  722. $source = file_url_transform_relative(file_create_url($src['uri']));
  723. if (isset($src['width']) && !empty($src['width'])) {
  724. $source .= ' ' . $src['width'];
  725. }
  726. elseif (isset($src['multiplier']) && !empty($src['multiplier'])) {
  727. $source .= ' ' . $src['multiplier'];
  728. }
  729. $srcset[] = $source;
  730. }
  731. $variables['attributes']['srcset'] = implode(', ', $srcset);
  732. }
  733. foreach (['width', 'height', 'alt', 'title', 'sizes'] as $key) {
  734. if (isset($variables[$key])) {
  735. // If the property has already been defined in the attributes,
  736. // do not override, including NULL.
  737. if (array_key_exists($key, $variables['attributes'])) {
  738. continue;
  739. }
  740. $variables['attributes'][$key] = $variables[$key];
  741. }
  742. }
  743. }
  744. /**
  745. * Prepares variables for table templates.
  746. *
  747. * Default template: table.html.twig.
  748. *
  749. * @param array $variables
  750. * An associative array containing:
  751. * - header: An array containing the table headers. Each element of the array
  752. * can be either a localized string or an associative array with the
  753. * following keys:
  754. * - data: The localized title of the table column, as a string or render
  755. * array.
  756. * - field: The database field represented in the table column (required
  757. * if user is to be able to sort on this column).
  758. * - sort: A default sort order for this column ("asc" or "desc"). Only
  759. * one column should be given a default sort order because table sorting
  760. * only applies to one column at a time.
  761. * - class: An array of values for the 'class' attribute. In particular,
  762. * the least important columns that can be hidden on narrow and medium
  763. * width screens should have a 'priority-low' class, referenced with the
  764. * RESPONSIVE_PRIORITY_LOW constant. Columns that should be shown on
  765. * medium+ wide screens should be marked up with a class of
  766. * 'priority-medium', referenced by with the RESPONSIVE_PRIORITY_MEDIUM
  767. * constant. Themes may hide columns with one of these two classes on
  768. * narrow viewports to save horizontal space.
  769. * - Any HTML attributes, such as "colspan", to apply to the column header
  770. * cell.
  771. * - rows: An array of table rows. Every row is an array of cells, or an
  772. * associative array with the following keys:
  773. * - data: An array of cells.
  774. * - Any HTML attributes, such as "class", to apply to the table row.
  775. * - no_striping: A Boolean indicating that the row should receive no
  776. * 'even / odd' styling. Defaults to FALSE.
  777. * Each cell can be either a string or an associative array with the
  778. * following keys:
  779. * - data: The string or render array to display in the table cell.
  780. * - header: Indicates this cell is a header.
  781. * - Any HTML attributes, such as "colspan", to apply to the table cell.
  782. * Here's an example for $rows:
  783. * @code
  784. * $rows = array(
  785. * // Simple row
  786. * array(
  787. * 'Cell 1', 'Cell 2', 'Cell 3'
  788. * ),
  789. * // Row with attributes on the row and some of its cells.
  790. * array(
  791. * 'data' => array('Cell 1', array('data' => 'Cell 2', 'colspan' => 2)), 'class' => array('funky')
  792. * ),
  793. * );
  794. * @endcode
  795. * - footer: An array of table rows which will be printed within a <tfoot>
  796. * tag, in the same format as the rows element (see above).
  797. * - attributes: An array of HTML attributes to apply to the table tag.
  798. * - caption: A localized string to use for the <caption> tag.
  799. * - colgroups: An array of column groups. Each element of the array can be
  800. * either:
  801. * - An array of columns, each of which is an associative array of HTML
  802. * attributes applied to the <col> element.
  803. * - An array of attributes applied to the <colgroup> element, which must
  804. * include a "data" attribute. To add attributes to <col> elements,
  805. * set the "data" attribute with an array of columns, each of which is an
  806. * associative array of HTML attributes.
  807. * Here's an example for $colgroup:
  808. * @code
  809. * $colgroup = array(
  810. * // <colgroup> with one <col> element.
  811. * array(
  812. * array(
  813. * 'class' => array('funky'), // Attribute for the <col> element.
  814. * ),
  815. * ),
  816. * // <colgroup> with attributes and inner <col> elements.
  817. * array(
  818. * 'data' => array(
  819. * array(
  820. * 'class' => array('funky'), // Attribute for the <col> element.
  821. * ),
  822. * ),
  823. * 'class' => array('jazzy'), // Attribute for the <colgroup> element.
  824. * ),
  825. * );
  826. * @endcode
  827. * These optional tags are used to group and set properties on columns
  828. * within a table. For example, one may easily group three columns and
  829. * apply same background style to all.
  830. * - sticky: Use a "sticky" table header.
  831. * - empty: The message to display in an extra row if table does not have any
  832. * rows.
  833. */
  834. function template_preprocess_table(&$variables) {
  835. // Format the table columns:
  836. if (!empty($variables['colgroups'])) {
  837. foreach ($variables['colgroups'] as &$colgroup) {
  838. // Check if we're dealing with a simple or complex column
  839. if (isset($colgroup['data'])) {
  840. $cols = $colgroup['data'];
  841. unset($colgroup['data']);
  842. $colgroup_attributes = $colgroup;
  843. }
  844. else {
  845. $cols = $colgroup;
  846. $colgroup_attributes = [];
  847. }
  848. $colgroup = [];
  849. $colgroup['attributes'] = new Attribute($colgroup_attributes);
  850. $colgroup['cols'] = [];
  851. // Build columns.
  852. if (is_array($cols) && !empty($cols)) {
  853. foreach ($cols as $col_key => $col) {
  854. $colgroup['cols'][$col_key]['attributes'] = new Attribute($col);
  855. }
  856. }
  857. }
  858. }
  859. // Build an associative array of responsive classes keyed by column.
  860. $responsive_classes = [];
  861. // Format the table header:
  862. $ts = [];
  863. $header_columns = 0;
  864. if (!empty($variables['header'])) {
  865. $ts = tablesort_init($variables['header']);
  866. // Use a separate index with responsive classes as headers
  867. // may be associative.
  868. $responsive_index = -1;
  869. foreach ($variables['header'] as $col_key => $cell) {
  870. // Increase the responsive index.
  871. $responsive_index++;
  872. if (!is_array($cell)) {
  873. $header_columns++;
  874. $cell_content = $cell;
  875. $cell_attributes = new Attribute();
  876. $is_header = TRUE;
  877. }
  878. else {
  879. if (isset($cell['colspan'])) {
  880. $header_columns += $cell['colspan'];
  881. }
  882. else {
  883. $header_columns++;
  884. }
  885. $cell_content = '';
  886. if (isset($cell['data'])) {
  887. $cell_content = $cell['data'];
  888. unset($cell['data']);
  889. }
  890. // Flag the cell as a header or not and remove the flag.
  891. $is_header = isset($cell['header']) ? $cell['header'] : TRUE;
  892. unset($cell['header']);
  893. // Track responsive classes for each column as needed. Only the header
  894. // cells for a column are marked up with the responsive classes by a
  895. // module developer or themer. The responsive classes on the header cells
  896. // must be transferred to the content cells.
  897. if (!empty($cell['class']) && is_array($cell['class'])) {
  898. if (in_array(RESPONSIVE_PRIORITY_MEDIUM, $cell['class'])) {
  899. $responsive_classes[$responsive_index] = RESPONSIVE_PRIORITY_MEDIUM;
  900. }
  901. elseif (in_array(RESPONSIVE_PRIORITY_LOW, $cell['class'])) {
  902. $responsive_classes[$responsive_index] = RESPONSIVE_PRIORITY_LOW;
  903. }
  904. }
  905. tablesort_header($cell_content, $cell, $variables['header'], $ts);
  906. // tablesort_header() removes the 'sort' and 'field' keys.
  907. $cell_attributes = new Attribute($cell);
  908. }
  909. $variables['header'][$col_key] = [];
  910. $variables['header'][$col_key]['tag'] = $is_header ? 'th' : 'td';
  911. $variables['header'][$col_key]['attributes'] = $cell_attributes;
  912. $variables['header'][$col_key]['content'] = $cell_content;
  913. }
  914. }
  915. $variables['header_columns'] = $header_columns;
  916. // Rows and footer have the same structure.
  917. $sections = ['rows' , 'footer'];
  918. foreach ($sections as $section) {
  919. if (!empty($variables[$section])) {
  920. foreach ($variables[$section] as $row_key => $row) {
  921. $cells = $row;
  922. $row_attributes = [];
  923. // Check if we're dealing with a simple or complex row
  924. if (isset($row['data'])) {
  925. $cells = $row['data'];
  926. $variables['no_striping'] = isset($row['no_striping']) ? $row['no_striping'] : FALSE;
  927. // Set the attributes array and exclude 'data' and 'no_striping'.
  928. $row_attributes = $row;
  929. unset($row_attributes['data']);
  930. unset($row_attributes['no_striping']);
  931. }
  932. // Build row.
  933. $variables[$section][$row_key] = [];
  934. $variables[$section][$row_key]['attributes'] = new Attribute($row_attributes);
  935. $variables[$section][$row_key]['cells'] = [];
  936. if (!empty($cells)) {
  937. // Reset the responsive index.
  938. $responsive_index = -1;
  939. foreach ($cells as $col_key => $cell) {
  940. // Increase the responsive index.
  941. $responsive_index++;
  942. if (!is_array($cell)) {
  943. $cell_content = $cell;
  944. $cell_attributes = [];
  945. $is_header = FALSE;
  946. }
  947. else {
  948. $cell_content = '';
  949. if (isset($cell['data'])) {
  950. $cell_content = $cell['data'];
  951. unset($cell['data']);
  952. }
  953. // Flag the cell as a header or not and remove the flag.
  954. $is_header = !empty($cell['header']);
  955. unset($cell['header']);
  956. $cell_attributes = $cell;
  957. }
  958. // Active table sort information.
  959. if (isset($variables['header'][$col_key]['data']) && $variables['header'][$col_key]['data'] == $ts['name'] && !empty($variables['header'][$col_key]['field'])) {
  960. $variables[$section][$row_key]['cells'][$col_key]['active_table_sort'] = TRUE;
  961. }
  962. // Copy RESPONSIVE_PRIORITY_LOW/RESPONSIVE_PRIORITY_MEDIUM
  963. // class from header to cell as needed.
  964. if (isset($responsive_classes[$responsive_index])) {
  965. $cell_attributes['class'][] = $responsive_classes[$responsive_index];
  966. }
  967. $variables[$section][$row_key]['cells'][$col_key]['tag'] = $is_header ? 'th' : 'td';
  968. $variables[$section][$row_key]['cells'][$col_key]['attributes'] = new Attribute($cell_attributes);
  969. $variables[$section][$row_key]['cells'][$col_key]['content'] = $cell_content;
  970. }
  971. }
  972. }
  973. }
  974. }
  975. if (empty($variables['no_striping'])) {
  976. $variables['attributes']['data-striping'] = 1;
  977. }
  978. }
  979. /**
  980. * Prepares variables for item list templates.
  981. *
  982. * Default template: item-list.html.twig.
  983. *
  984. * @param array $variables
  985. * An associative array containing:
  986. * - items: An array of items to be displayed in the list. Each item can be
  987. * either a string or a render array. If #type, #theme, or #markup
  988. * properties are not specified for child render arrays, they will be
  989. * inherited from the parent list, allowing callers to specify larger
  990. * nested lists without having to explicitly specify and repeat the
  991. * render properties for all nested child lists.
  992. * - title: A title to be prepended to the list.
  993. * - list_type: The type of list to return (e.g. "ul", "ol").
  994. * - wrapper_attributes: HTML attributes to be applied to the list wrapper.
  995. *
  996. * @see https://www.drupal.org/node/1842756
  997. */
  998. function template_preprocess_item_list(&$variables) {
  999. $variables['wrapper_attributes'] = new Attribute($variables['wrapper_attributes']);
  1000. foreach ($variables['items'] as &$item) {
  1001. $attributes = [];
  1002. // If the item value is an array, then it is a render array.
  1003. if (is_array($item)) {
  1004. // List items support attributes via the '#wrapper_attributes' property.
  1005. if (isset($item['#wrapper_attributes'])) {
  1006. $attributes = $item['#wrapper_attributes'];
  1007. }
  1008. // Determine whether there are any child elements in the item that are not
  1009. // fully-specified render arrays. If there are any, then the child
  1010. // elements present nested lists and we automatically inherit the render
  1011. // array properties of the current list to them.
  1012. foreach (Element::children($item) as $key) {
  1013. $child = &$item[$key];
  1014. // If this child element does not specify how it can be rendered, then
  1015. // we need to inherit the render properties of the current list.
  1016. if (!isset($child['#type']) && !isset($child['#theme']) && !isset($child['#markup'])) {
  1017. // Since item-list.html.twig supports both strings and render arrays
  1018. // as items, the items of the nested list may have been specified as
  1019. // the child elements of the nested list, instead of #items. For
  1020. // convenience, we automatically move them into #items.
  1021. if (!isset($child['#items'])) {
  1022. // This is the same condition as in
  1023. // \Drupal\Core\Render\Element::children(), which cannot be used
  1024. // here, since it triggers an error on string values.
  1025. foreach ($child as $child_key => $child_value) {
  1026. if ($child_key[0] !== '#') {
  1027. $child['#items'][$child_key] = $child_value;
  1028. unset($child[$child_key]);
  1029. }
  1030. }
  1031. }
  1032. // Lastly, inherit the original theme variables of the current list.
  1033. $child['#theme'] = $variables['theme_hook_original'];
  1034. $child['#list_type'] = $variables['list_type'];
  1035. }
  1036. }
  1037. }
  1038. // Set the item's value and attributes for the template.
  1039. $item = [
  1040. 'value' => $item,
  1041. 'attributes' => new Attribute($attributes),
  1042. ];
  1043. }
  1044. }
  1045. /**
  1046. * Prepares variables for container templates.
  1047. *
  1048. * Default template: container.html.twig.
  1049. *
  1050. * @param array $variables
  1051. * An associative array containing:
  1052. * - element: An associative array containing the properties of the element.
  1053. * Properties used: #id, #attributes, #children.
  1054. */
  1055. function template_preprocess_container(&$variables) {
  1056. $variables['has_parent'] = FALSE;
  1057. $element = $variables['element'];
  1058. // Ensure #attributes is set.
  1059. $element += ['#attributes' => []];
  1060. // Special handling for form elements.
  1061. if (isset($element['#array_parents'])) {
  1062. // Assign an html ID.
  1063. if (!isset($element['#attributes']['id'])) {
  1064. $element['#attributes']['id'] = $element['#id'];
  1065. }
  1066. $variables['has_parent'] = TRUE;
  1067. }
  1068. $variables['children'] = $element['#children'];
  1069. $variables['attributes'] = $element['#attributes'];
  1070. }
  1071. /**
  1072. * Prepares variables for maintenance task list templates.
  1073. *
  1074. * Default template: maintenance-task-list.html.twig.
  1075. *
  1076. * @param array $variables
  1077. * An associative array containing:
  1078. * - items: An associative array of maintenance tasks.
  1079. * It's the caller's responsibility to ensure this array's items contain no
  1080. * dangerous HTML such as <script> tags.
  1081. * - active: The key for the currently active maintenance task.
  1082. */
  1083. function template_preprocess_maintenance_task_list(&$variables) {
  1084. $items = $variables['items'];
  1085. $active = $variables['active'];
  1086. $done = isset($items[$active]) || $active == NULL;
  1087. foreach ($items as $k => $item) {
  1088. $variables['tasks'][$k]['item'] = $item;
  1089. $variables['tasks'][$k]['attributes'] = new Attribute();
  1090. if ($active == $k) {
  1091. $variables['tasks'][$k]['attributes']->addClass('is-active');
  1092. $variables['tasks'][$k]['status'] = t('active');
  1093. $done = FALSE;
  1094. }
  1095. else {
  1096. if ($done) {
  1097. $variables['tasks'][$k]['attributes']->addClass('done');
  1098. $variables['tasks'][$k]['status'] = t('done');
  1099. }
  1100. }
  1101. }
  1102. }
  1103. /**
  1104. * Adds a default set of helper variables for preprocessors and templates.
  1105. *
  1106. * This function is called for every theme hook. It is the first in the
  1107. * sequence of preprocessing functions called when preparing variables for a
  1108. * template.
  1109. *
  1110. * See the @link themeable Default theme implementations topic @endlink for
  1111. * details.
  1112. */
  1113. function template_preprocess(&$variables, $hook, $info) {
  1114. // Merge in variables that don't depend on hook and don't change during a
  1115. // single page request.
  1116. // Use the advanced drupal_static() pattern, since this is called very often.
  1117. static $drupal_static_fast;
  1118. if (!isset($drupal_static_fast)) {
  1119. $drupal_static_fast['default_variables'] = &drupal_static(__FUNCTION__);
  1120. }
  1121. $default_variables = &$drupal_static_fast['default_variables'];
  1122. if (!isset($default_variables)) {
  1123. $default_variables = _template_preprocess_default_variables();
  1124. }
  1125. $variables += $default_variables;
  1126. // When theming a render element, merge its #attributes into
  1127. // $variables['attributes'].
  1128. if (isset($info['render element'])) {
  1129. $key = $info['render element'];
  1130. if (isset($variables[$key]['#attributes'])) {
  1131. $variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], $variables[$key]['#attributes']);
  1132. }
  1133. }
  1134. }
  1135. /**
  1136. * Returns hook-independent variables to template_preprocess().
  1137. */
  1138. function _template_preprocess_default_variables() {
  1139. // Variables that don't depend on a database connection.
  1140. $variables = [
  1141. 'attributes' => [],
  1142. 'title_attributes' => [],
  1143. 'content_attributes' => [],
  1144. 'title_prefix' => [],
  1145. 'title_suffix' => [],
  1146. 'db_is_active' => !defined('MAINTENANCE_MODE'),
  1147. 'is_admin' => FALSE,
  1148. 'logged_in' => FALSE,
  1149. ];
  1150. // Give modules a chance to alter the default template variables.
  1151. \Drupal::moduleHandler()->alter('template_preprocess_default_variables', $variables);
  1152. // Tell all templates where they are located.
  1153. $variables['directory'] = \Drupal::theme()->getActiveTheme()->getPath();
  1154. return $variables;
  1155. }
  1156. /**
  1157. * Prepares variables for HTML document templates.
  1158. *
  1159. * Default template: html.html.twig.
  1160. *
  1161. * @param array $variables
  1162. * An associative array containing:
  1163. * - page: A render element representing the page.
  1164. */
  1165. function template_preprocess_html(&$variables) {
  1166. $variables['page'] = $variables['html']['page'];
  1167. unset($variables['html']['page']);
  1168. $variables['page_top'] = NULL;
  1169. if (isset($variables['html']['page_top'])) {
  1170. $variables['page_top'] = $variables['html']['page_top'];
  1171. unset($variables['html']['page_top']);
  1172. }
  1173. $variables['page_bottom'] = NULL;
  1174. if (isset($variables['html']['page_bottom'])) {
  1175. $variables['page_bottom'] = $variables['html']['page_bottom'];
  1176. unset($variables['html']['page_bottom']);
  1177. }
  1178. $variables['html_attributes'] = new Attribute();
  1179. // <html> element attributes.
  1180. $language_interface = \Drupal::languageManager()->getCurrentLanguage();
  1181. $variables['html_attributes']['lang'] = $language_interface->getId();
  1182. $variables['html_attributes']['dir'] = $language_interface->getDirection();
  1183. if (isset($variables['db_is_active']) && !$variables['db_is_active']) {
  1184. $variables['db_offline'] = TRUE;
  1185. }
  1186. // Add a variable for the root path. This can be used to create a class and
  1187. // theme the page depending on the current path (e.g. node, admin, user) as
  1188. // well as more specific data like path-frontpage.
  1189. $is_front_page = \Drupal::service('path.matcher')->isFrontPage();
  1190. if ($is_front_page) {
  1191. $variables['root_path'] = FALSE;
  1192. }
  1193. else {
  1194. $system_path = \Drupal::service('path.current')->getPath();
  1195. $variables['root_path'] = explode('/', $system_path)[1];
  1196. }
  1197. $site_config = \Drupal::config('system.site');
  1198. // Construct page title.
  1199. if (isset($variables['page']['#title']) && is_array($variables['page']['#title'])) {
  1200. // Do an early render if the title is a render array.
  1201. $variables['page']['#title'] = (string) \Drupal::service('renderer')->render($variables['page']['#title']);
  1202. }
  1203. if (!empty($variables['page']['#title'])) {
  1204. $head_title = [
  1205. // Marking the title as safe since it has had the tags stripped.
  1206. 'title' => Markup::create(trim(strip_tags($variables['page']['#title']))),
  1207. 'name' => $site_config->get('name'),
  1208. ];
  1209. }
  1210. // @todo Remove once views is not bypassing the view subscriber anymore.
  1211. // @see https://www.drupal.org/node/2068471
  1212. elseif ($is_front_page) {
  1213. $head_title = [
  1214. 'title' => t('Home'),
  1215. 'name' => $site_config->get('name'),
  1216. ];
  1217. }
  1218. else {
  1219. $head_title = ['name' => $site_config->get('name')];
  1220. if ($site_config->get('slogan')) {
  1221. $head_title['slogan'] = strip_tags($site_config->get('slogan'));
  1222. }
  1223. }
  1224. $variables['head_title'] = $head_title;
  1225. // @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
  1226. $variables['head_title_array'] = $head_title;
  1227. // Create placeholder strings for these keys.
  1228. // @see \Drupal\Core\Render\HtmlResponseSubscriber
  1229. $types = [
  1230. 'styles' => 'css',
  1231. 'scripts' => 'js',
  1232. 'scripts_bottom' => 'js-bottom',
  1233. 'head' => 'head',
  1234. ];
  1235. $variables['placeholder_token'] = Crypt::randomBytesBase64(55);
  1236. foreach ($types as $type => $placeholder_name) {
  1237. $placeholder = '<' . $placeholder_name . '-placeholder token="' . $variables['placeholder_token'] . '">';
  1238. $variables['#attached']['html_response_attachment_placeholders'][$type] = $placeholder;
  1239. }
  1240. }
  1241. /**
  1242. * Prepares variables for the page template.
  1243. *
  1244. * Default template: page.html.twig.
  1245. *
  1246. * See the page.html.twig template for the list of variables.
  1247. */
  1248. function template_preprocess_page(&$variables) {
  1249. $language_interface = \Drupal::languageManager()->getCurrentLanguage();
  1250. foreach (\Drupal::theme()->getActiveTheme()->getRegions() as $region) {
  1251. if (!isset($variables['page'][$region])) {
  1252. $variables['page'][$region] = [];
  1253. }
  1254. }
  1255. $variables['base_path'] = base_path();
  1256. $variables['front_page'] = \Drupal::url('<front>');
  1257. $variables['language'] = $language_interface;
  1258. // An exception might be thrown.
  1259. try {
  1260. $variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
  1261. }
  1262. catch (Exception $e) {
  1263. // If the database is not yet available, set default values for these
  1264. // variables.
  1265. $variables['is_front'] = FALSE;
  1266. $variables['db_is_active'] = FALSE;
  1267. }
  1268. if ($node = \Drupal::routeMatch()->getParameter('node')) {
  1269. $variables['node'] = $node;
  1270. }
  1271. }
  1272. /**
  1273. * Generate an array of suggestions from path arguments.
  1274. *
  1275. * This is typically called for adding to the suggestions in
  1276. * hook_theme_suggestions_HOOK_alter() or adding to 'attributes' class key
  1277. * variables from within preprocess functions, when wanting to base the
  1278. * additional suggestions or classes on the path of the current page.
  1279. *
  1280. * @param $args
  1281. * An array of path arguments.
  1282. * @param $base
  1283. * A string identifying the base 'thing' from which more specific suggestions
  1284. * are derived. For example, 'page' or 'html'.
  1285. * @param $delimiter
  1286. * The string used to delimit increasingly specific information. The default
  1287. * of '__' is appropriate for theme hook suggestions. '-' is appropriate for
  1288. * extra classes.
  1289. *
  1290. * @return
  1291. * An array of suggestions, suitable for adding to
  1292. * hook_theme_suggestions_HOOK_alter() or to $variables['attributes']['class']
  1293. * if the suggestions represent extra CSS classes.
  1294. */
  1295. function theme_get_suggestions($args, $base, $delimiter = '__') {
  1296. // Build a list of suggested theme hooks in order of
  1297. // specificity. One suggestion is made for every element of the current path,
  1298. // though numeric elements are not carried to subsequent suggestions. For
  1299. // example, for $base='page', http://www.example.com/node/1/edit would result
  1300. // in the following suggestions:
  1301. //
  1302. // page__node
  1303. // page__node__%
  1304. // page__node__1
  1305. // page__node__edit
  1306. $suggestions = [];
  1307. $prefix = $base;
  1308. foreach ($args as $arg) {
  1309. // Remove slashes or null per SA-CORE-2009-003 and change - (hyphen) to _
  1310. // (underscore).
  1311. //
  1312. // When we discover templates in @see drupal_find_theme_templates,
  1313. // hyphens (-) are converted to underscores (_) before the theme hook
  1314. // is registered. We do this because the hyphens used for delimiters
  1315. // in hook suggestions cannot be used in the function names of the
  1316. // associated preprocess functions. Any page templates designed to be used
  1317. // on paths that contain a hyphen are also registered with these hyphens
  1318. // converted to underscores so here we must convert any hyphens in path
  1319. // arguments to underscores here before fetching theme hook suggestions
  1320. // to ensure the templates are appropriately recognized.
  1321. $arg = str_replace(["/", "\\", "\0", '-'], ['', '', '', '_'], $arg);
  1322. // The percent acts as a wildcard for numeric arguments since
  1323. // asterisks are not valid filename characters on many filesystems.
  1324. if (is_numeric($arg)) {
  1325. $suggestions[] = $prefix . $delimiter . '%';
  1326. }
  1327. $suggestions[] = $prefix . $delimiter . $arg;
  1328. if (!is_numeric($arg)) {
  1329. $prefix .= $delimiter . $arg;
  1330. }
  1331. }
  1332. if (\Drupal::service('path.matcher')->isFrontPage()) {
  1333. // Front templates should be based on root only, not prefixed arguments.
  1334. $suggestions[] = $base . $delimiter . 'front';
  1335. }
  1336. return $suggestions;
  1337. }
  1338. /**
  1339. * Prepares variables for maintenance page templates.
  1340. *
  1341. * Default template: maintenance-page.html.twig.
  1342. *
  1343. * @param array $variables
  1344. * An associative array containing:
  1345. * - content - An array of page content.
  1346. *
  1347. * @see system_page_attachments()
  1348. */
  1349. function template_preprocess_maintenance_page(&$variables) {
  1350. // @todo Rename the templates to page--maintenance + page--install.
  1351. template_preprocess_page($variables);
  1352. // @see system_page_attachments()
  1353. $variables['#attached']['library'][] = 'system/maintenance';
  1354. // Maintenance page and install page need branding info in variables because
  1355. // there is no blocks.
  1356. $site_config = \Drupal::config('system.site');
  1357. $variables['logo'] = theme_get_setting('logo.url');
  1358. $variables['site_name'] = $site_config->get('name');
  1359. $variables['site_slogan'] = $site_config->get('slogan');
  1360. // Maintenance page and install page need page title in variable because there
  1361. // are no blocks.
  1362. $variables['title'] = $variables['page']['#title'];
  1363. }
  1364. /**
  1365. * Prepares variables for install page templates.
  1366. *
  1367. * Default template: install-page.html.twig.
  1368. *
  1369. * @param array $variables
  1370. * An associative array containing:
  1371. * - content - An array of page content.
  1372. *
  1373. * @see template_preprocess_maintenance_page()
  1374. */
  1375. function template_preprocess_install_page(&$variables) {
  1376. template_preprocess_maintenance_page($variables);
  1377. // Override the site name that is displayed on the page, since Drupal is
  1378. // still in the process of being installed.
  1379. $distribution_name = drupal_install_profile_distribution_name();
  1380. $variables['site_name'] = $distribution_name;
  1381. $variables['site_version'] = drupal_install_profile_distribution_version();
  1382. }
  1383. /**
  1384. * Prepares variables for region templates.
  1385. *
  1386. * Default template: region.html.twig.
  1387. *
  1388. * Prepares the values passed to the theme_region function to be passed into a
  1389. * pluggable template engine. Uses the region name to generate a template file
  1390. * suggestions.
  1391. *
  1392. * @param array $variables
  1393. * An associative array containing:
  1394. * - elements: An associative array containing properties of the region.
  1395. */
  1396. function template_preprocess_region(&$variables) {
  1397. // Create the $content variable that templates expect.
  1398. $variables['content'] = $variables['elements']['#children'];
  1399. $variables['region'] = $variables['elements']['#region'];
  1400. }
  1401. /**
  1402. * Prepares variables for field templates.
  1403. *
  1404. * Default template: field.html.twig.
  1405. *
  1406. * @param array $variables
  1407. * An associative array containing:
  1408. * - element: A render element representing the field.
  1409. * - attributes: A string containing the attributes for the wrapping div.
  1410. * - title_attributes: A string containing the attributes for the title.
  1411. */
  1412. function template_preprocess_field(&$variables, $hook) {
  1413. $element = $variables['element'];
  1414. // Creating variables for the template.
  1415. $variables['entity_type'] = $element['#entity_type'];
  1416. $variables['field_name'] = $element['#field_name'];
  1417. $variables['field_type'] = $element['#field_type'];
  1418. $variables['label_display'] = $element['#label_display'];
  1419. $variables['label_hidden'] = ($element['#label_display'] == 'hidden');
  1420. // Always set the field label - allow themes to decide whether to display it.
  1421. // In addition the label should be rendered but hidden to support screen
  1422. // readers.
  1423. $variables['label'] = $element['#title'];
  1424. $variables['multiple'] = $element['#is_multiple'];
  1425. static $default_attributes;
  1426. if (!isset($default_attributes)) {
  1427. $default_attributes = new Attribute();
  1428. }
  1429. // Merge attributes when a single-value field has a hidden label.
  1430. if ($element['#label_display'] == 'hidden' && !$variables['multiple'] && !empty($element['#items'][0]->_attributes)) {
  1431. $variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], (array) $element['#items'][0]->_attributes);
  1432. }
  1433. // We want other preprocess functions and the theme implementation to have
  1434. // fast access to the field item render arrays. The item render array keys
  1435. // (deltas) should always be numerically indexed starting from 0, and looping
  1436. // on those keys is faster than calling Element::children() or looping on all
  1437. // keys within $element, since that requires traversal of all element
  1438. // properties.
  1439. $variables['items'] = [];
  1440. $delta = 0;
  1441. while (!empty($element[$delta])) {
  1442. $variables['items'][$delta]['content'] = $element[$delta];
  1443. // Modules (e.g., rdf.module) can add field item attributes (to
  1444. // $item->_attributes) within hook_entity_prepare_view(). Some field
  1445. // formatters move those attributes into some nested formatter-specific
  1446. // element in order have them rendered on the desired HTML element (e.g., on
  1447. // the <a> element of a field item being rendered as a link). Other field
  1448. // formatters leave them within $element['#items'][$delta]['_attributes'] to
  1449. // be rendered on the item wrappers provided by field.html.twig.
  1450. $variables['items'][$delta]['attributes'] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : clone($default_attributes);
  1451. $delta++;
  1452. }
  1453. }
  1454. /**
  1455. * Prepares variables for individual form element templates.
  1456. *
  1457. * Default template: field-multiple-value-form.html.twig.
  1458. *
  1459. * Combines multiple values into a table with drag-n-drop reordering.
  1460. *
  1461. * @param array $variables
  1462. * An associative array containing:
  1463. * - element: A render element representing the form element.
  1464. */
  1465. function template_preprocess_field_multiple_value_form(&$variables) {
  1466. $element = $variables['element'];
  1467. $variables['multiple'] = $element['#cardinality_multiple'];
  1468. if ($variables['multiple']) {
  1469. $table_id = Html::getUniqueId($element['#field_name'] . '_values');
  1470. $order_class = $element['#field_name'] . '-delta-order';
  1471. $header_attributes = new Attribute(['class' => ['label']]);
  1472. if (!empty($element['#required'])) {
  1473. $header_attributes['class'][] = 'js-form-required';
  1474. $header_attributes['class'][] = 'form-required';
  1475. }
  1476. $header = [
  1477. [
  1478. 'data' => [
  1479. '#prefix' => '<h4' . $header_attributes . '>',
  1480. '#markup' => $element['#title'],
  1481. '#suffix' => '</h4>',
  1482. ],
  1483. 'colspan' => 2,
  1484. 'class' => ['field-label'],
  1485. ],
  1486. t('Order', [], ['context' => 'Sort order']),
  1487. ];
  1488. $rows = [];
  1489. // Sort items according to '_weight' (needed when the form comes back after
  1490. // preview or failed validation).
  1491. $items = [];
  1492. $variables['button'] = [];
  1493. foreach (Element::children($element) as $key) {
  1494. if ($key === 'add_more') {
  1495. $variables['button'] = &$element[$key];
  1496. }
  1497. else {
  1498. $items[] = &$element[$key];
  1499. }
  1500. }
  1501. usort($items, '_field_multiple_value_form_sort_helper');
  1502. // Add the items as table rows.
  1503. foreach ($items as $item) {
  1504. $item['_weight']['#attributes']['class'] = [$order_class];
  1505. // Remove weight form element from item render array so it can be rendered
  1506. // in a separate table column.
  1507. $delta_element = $item['_weight'];
  1508. unset($item['_weight']);
  1509. $cells = [
  1510. ['data' => '', 'class' => ['field-multiple-drag']],
  1511. ['data' => $item],
  1512. ['data' => $delta_element, 'class' => ['delta-order']],
  1513. ];
  1514. $rows[] = [
  1515. 'data' => $cells,
  1516. 'class' => ['draggable'],
  1517. ];
  1518. }
  1519. $variables['table'] = [
  1520. '#type' => 'table',
  1521. '#header' => $header,
  1522. '#rows' => $rows,
  1523. '#attributes' => [
  1524. 'id' => $table_id,
  1525. 'class' => ['field-multiple-table'],
  1526. ],
  1527. '#tabledrag' => [
  1528. [
  1529. 'action' => 'order',
  1530. 'relationship' => 'sibling',
  1531. 'group' => $order_class,
  1532. ],
  1533. ],
  1534. ];
  1535. if (!empty($element['#description'])) {
  1536. $description_id = $element['#attributes']['aria-describedby'];
  1537. $description_attributes['id'] = $description_id;
  1538. $variables['description']['attributes'] = new Attribute($description_attributes);
  1539. $variables['description']['content'] = $element['#description'];
  1540. // Add the description's id to the table aria attributes.
  1541. $variables['table']['#attributes']['aria-describedby'] = $element['#attributes']['aria-describedby'];
  1542. }
  1543. }
  1544. else {
  1545. $variables['elements'] = [];
  1546. foreach (Element::children($element) as $key) {
  1547. $variables['elements'][] = $element[$key];
  1548. }
  1549. }
  1550. }
  1551. /**
  1552. * Prepares variables for breadcrumb templates.
  1553. *
  1554. * Default template: breadcrumb.html.twig.
  1555. *
  1556. * @param array $variables
  1557. * An associative array containing:
  1558. * - links: A list of \Drupal\Core\Link objects which should be rendered.
  1559. */
  1560. function template_preprocess_breadcrumb(&$variables) {
  1561. $variables['breadcrumb'] = [];
  1562. /** @var \Drupal\Core\Link $link */
  1563. foreach ($variables['links'] as $key => $link) {
  1564. $variables['breadcrumb'][$key] = ['text' => $link->getText(), 'url' => $link->getUrl()->toString()];
  1565. }
  1566. }
  1567. /**
  1568. * Callback for usort() within template_preprocess_field_multiple_value_form().
  1569. *
  1570. * Sorts using ['_weight']['#value']
  1571. */
  1572. function _field_multiple_value_form_sort_helper($a, $b) {
  1573. $a_weight = (is_array($a) && isset($a['_weight']['#value']) ? $a['_weight']['#value'] : 0);
  1574. $b_weight = (is_array($b) && isset($b['_weight']['#value']) ? $b['_weight']['#value'] : 0);
  1575. return $a_weight - $b_weight;
  1576. }
  1577. /**
  1578. * Provides theme registration for themes across .inc files.
  1579. */
  1580. function drupal_common_theme() {
  1581. return [
  1582. // From theme.inc.
  1583. 'html' => [
  1584. 'render element' => 'html',
  1585. ],
  1586. 'page' => [
  1587. 'render element' => 'page',
  1588. ],
  1589. 'page_title' => [
  1590. 'variables' => ['title' => NULL],
  1591. ],
  1592. 'region' => [
  1593. 'render element' => 'elements',
  1594. ],
  1595. 'time' => [
  1596. 'variables' => ['timestamp' => NULL, 'text' => NULL, 'attributes' => []],
  1597. ],
  1598. 'datetime_form' => [
  1599. 'render element' => 'element',
  1600. ],
  1601. 'datetime_wrapper' => [
  1602. 'render element' => 'element',
  1603. ],
  1604. 'status_messages' => [
  1605. 'variables' => ['status_headings' => [], 'message_list' => NULL],
  1606. ],
  1607. 'links' => [
  1608. 'variables' => ['links' => [], 'attributes' => ['class' => ['links']], 'heading' => [], 'set_active_class' => FALSE],
  1609. ],
  1610. 'dropbutton_wrapper' => [
  1611. 'variables' => ['children' => NULL],
  1612. ],
  1613. 'image' => [
  1614. // HTML 4 and XHTML 1.0 always require an alt attribute. The HTML 5 draft
  1615. // allows the alt attribute to be omitted in some cases. Therefore,
  1616. // default the alt attribute to an empty string, but allow code providing
  1617. // variables to image.html.twig templates to pass explicit NULL for it to
  1618. // be omitted. Usually, neither omission nor an empty string satisfies
  1619. // accessibility requirements, so it is strongly encouraged for code
  1620. // building variables for image.html.twig templates to pass a meaningful
  1621. // value for the alt variable.
  1622. // - http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.8
  1623. // - http://www.w3.org/TR/xhtml1/dtds.html
  1624. // - http://dev.w3.org/html5/spec/Overview.html#alt
  1625. // The title attribute is optional in all cases, so it is omitted by
  1626. // default.
  1627. 'variables' => ['uri' => NULL, 'width' => NULL, 'height' => NULL, 'alt' => '', 'title' => NULL, 'attributes' => [], 'sizes' => NULL, 'srcset' => [], 'style_name' => NULL],
  1628. ],
  1629. 'breadcrumb' => [
  1630. 'variables' => ['links' => []],
  1631. ],
  1632. 'table' => [
  1633. 'variables' => ['header' => NULL, 'rows' => NULL, 'footer' => NULL, 'attributes' => [], 'caption' => NULL, 'colgroups' => [], 'sticky' => FALSE, 'responsive' => TRUE, 'empty' => ''],
  1634. ],
  1635. 'tablesort_indicator' => [
  1636. 'variables' => ['style' => NULL],
  1637. ],
  1638. 'mark' => [
  1639. 'variables' => ['status' => MARK_NEW],
  1640. ],
  1641. 'item_list' => [
  1642. 'variables' => ['items' => [], 'title' => '', 'list_type' => 'ul', 'wrapper_attributes' => [], 'attributes' => [], 'empty' => NULL, 'context' => []],
  1643. ],
  1644. 'feed_icon' => [
  1645. 'variables' => ['url' => NULL, 'title' => NULL],
  1646. ],
  1647. 'progress_bar' => [
  1648. 'variables' => ['label' => NULL, 'percent' => NULL, 'message' => NULL],
  1649. ],
  1650. 'indentation' => [
  1651. 'variables' => ['size' => 1],
  1652. ],
  1653. // From theme.maintenance.inc.
  1654. 'maintenance_page' => [
  1655. 'render element' => 'page',
  1656. ],
  1657. 'install_page' => [
  1658. 'render element' => 'page',
  1659. ],
  1660. 'maintenance_task_list' => [
  1661. 'variables' => ['items' => NULL, 'active' => NULL, 'variant' => NULL],
  1662. ],
  1663. 'authorize_report' => [
  1664. 'variables' => ['messages' => [], 'attributes' => []],
  1665. 'includes' => ['core/includes/theme.maintenance.inc'],
  1666. 'template' => 'authorize-report',
  1667. ],
  1668. // From pager.inc.
  1669. 'pager' => [
  1670. 'render element' => 'pager',
  1671. ],
  1672. // From menu.inc.
  1673. 'menu' => [
  1674. 'variables' => ['menu_name' => NULL, 'items' => [], 'attributes' => []],
  1675. ],
  1676. 'menu_local_task' => [
  1677. 'render element' => 'element',
  1678. ],
  1679. 'menu_local_action' => [
  1680. 'render element' => 'element',
  1681. ],
  1682. 'menu_local_tasks' => [
  1683. 'variables' => ['primary' => [], 'secondary' => []],
  1684. ],
  1685. // From form.inc.
  1686. 'input' => [
  1687. 'render element' => 'element',
  1688. ],
  1689. 'select' => [
  1690. 'render element' => 'element',
  1691. ],
  1692. 'fieldset' => [
  1693. 'render element' => 'element',
  1694. ],
  1695. 'details' => [
  1696. 'render element' => 'element',
  1697. ],
  1698. 'radios' => [
  1699. 'render element' => 'element',
  1700. ],
  1701. 'checkboxes' => [
  1702. 'render element' => 'element',
  1703. ],
  1704. 'form' => [
  1705. 'render element' => 'element',
  1706. ],
  1707. 'textarea' => [
  1708. 'render element' => 'element',
  1709. ],
  1710. 'form_element' => [
  1711. 'render element' => 'element',
  1712. ],
  1713. 'form_element_label' => [
  1714. 'render element' => 'element',
  1715. ],
  1716. 'vertical_tabs' => [
  1717. 'render element' => 'element',
  1718. ],
  1719. 'container' => [
  1720. 'render element' => 'element',
  1721. ],
  1722. // From field system.
  1723. 'field' => [
  1724. 'render element' => 'element',
  1725. ],
  1726. 'field_multiple_value_form' => [
  1727. 'render element' => 'element',
  1728. ],
  1729. ];
  1730. }