theme.inc 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868
  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 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 theme hooks implemented as templates only, not
  1107. * for theme hooks implemented as functions. This preprocess function is the
  1108. * first in the sequence of preprocessing functions that are called when
  1109. * preparing variables for a template.
  1110. *
  1111. * See the @link themeable Default theme implementations topic @endlink for
  1112. * details.
  1113. */
  1114. function template_preprocess(&$variables, $hook, $info) {
  1115. // Merge in variables that don't depend on hook and don't change during a
  1116. // single page request.
  1117. // Use the advanced drupal_static() pattern, since this is called very often.
  1118. static $drupal_static_fast;
  1119. if (!isset($drupal_static_fast)) {
  1120. $drupal_static_fast['default_variables'] = &drupal_static(__FUNCTION__);
  1121. }
  1122. $default_variables = &$drupal_static_fast['default_variables'];
  1123. if (!isset($default_variables)) {
  1124. $default_variables = _template_preprocess_default_variables();
  1125. }
  1126. $variables += $default_variables;
  1127. // When theming a render element, merge its #attributes into
  1128. // $variables['attributes'].
  1129. if (isset($info['render element'])) {
  1130. $key = $info['render element'];
  1131. if (isset($variables[$key]['#attributes'])) {
  1132. $variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], $variables[$key]['#attributes']);
  1133. }
  1134. }
  1135. }
  1136. /**
  1137. * Returns hook-independent variables to template_preprocess().
  1138. */
  1139. function _template_preprocess_default_variables() {
  1140. // Variables that don't depend on a database connection.
  1141. $variables = [
  1142. 'attributes' => [],
  1143. 'title_attributes' => [],
  1144. 'content_attributes' => [],
  1145. 'title_prefix' => [],
  1146. 'title_suffix' => [],
  1147. 'db_is_active' => !defined('MAINTENANCE_MODE'),
  1148. 'is_admin' => FALSE,
  1149. 'logged_in' => FALSE,
  1150. ];
  1151. // Give modules a chance to alter the default template variables.
  1152. \Drupal::moduleHandler()->alter('template_preprocess_default_variables', $variables);
  1153. // Tell all templates where they are located.
  1154. $variables['directory'] = \Drupal::theme()->getActiveTheme()->getPath();
  1155. return $variables;
  1156. }
  1157. /**
  1158. * Prepares variables for HTML document templates.
  1159. *
  1160. * Default template: html.html.twig.
  1161. *
  1162. * @param array $variables
  1163. * An associative array containing:
  1164. * - page: A render element representing the page.
  1165. */
  1166. function template_preprocess_html(&$variables) {
  1167. $variables['page'] = $variables['html']['page'];
  1168. unset($variables['html']['page']);
  1169. $variables['page_top'] = NULL;
  1170. if (isset($variables['html']['page_top'])) {
  1171. $variables['page_top'] = $variables['html']['page_top'];
  1172. unset($variables['html']['page_top']);
  1173. }
  1174. $variables['page_bottom'] = NULL;
  1175. if (isset($variables['html']['page_bottom'])) {
  1176. $variables['page_bottom'] = $variables['html']['page_bottom'];
  1177. unset($variables['html']['page_bottom']);
  1178. }
  1179. $variables['html_attributes'] = new Attribute();
  1180. // <html> element attributes.
  1181. $language_interface = \Drupal::languageManager()->getCurrentLanguage();
  1182. $variables['html_attributes']['lang'] = $language_interface->getId();
  1183. $variables['html_attributes']['dir'] = $language_interface->getDirection();
  1184. if (isset($variables['db_is_active']) && !$variables['db_is_active']) {
  1185. $variables['db_offline'] = TRUE;
  1186. }
  1187. // Add a variable for the root path. This can be used to create a class and
  1188. // theme the page depending on the current path (e.g. node, admin, user) as
  1189. // well as more specific data like path-frontpage.
  1190. $is_front_page = \Drupal::service('path.matcher')->isFrontPage();
  1191. if ($is_front_page) {
  1192. $variables['root_path'] = FALSE;
  1193. }
  1194. else {
  1195. $system_path = \Drupal::service('path.current')->getPath();
  1196. $variables['root_path'] = explode('/', $system_path)[1];
  1197. }
  1198. $site_config = \Drupal::config('system.site');
  1199. // Construct page title.
  1200. if (isset($variables['page']['#title']) && is_array($variables['page']['#title'])) {
  1201. // Do an early render if the title is a render array.
  1202. $variables['page']['#title'] = (string) \Drupal::service('renderer')->render($variables['page']['#title']);
  1203. }
  1204. if (!empty($variables['page']['#title'])) {
  1205. $head_title = [
  1206. // Marking the title as safe since it has had the tags stripped.
  1207. 'title' => Markup::create(trim(strip_tags($variables['page']['#title']))),
  1208. 'name' => $site_config->get('name'),
  1209. ];
  1210. }
  1211. // @todo Remove once views is not bypassing the view subscriber anymore.
  1212. // @see https://www.drupal.org/node/2068471
  1213. elseif ($is_front_page) {
  1214. $head_title = [
  1215. 'title' => t('Home'),
  1216. 'name' => $site_config->get('name'),
  1217. ];
  1218. }
  1219. else {
  1220. $head_title = ['name' => $site_config->get('name')];
  1221. if ($site_config->get('slogan')) {
  1222. $head_title['slogan'] = strip_tags($site_config->get('slogan'));
  1223. }
  1224. }
  1225. $variables['head_title'] = $head_title;
  1226. // @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0.
  1227. $variables['head_title_array'] = $head_title;
  1228. // Create placeholder strings for these keys.
  1229. // @see \Drupal\Core\Render\HtmlResponseSubscriber
  1230. $types = [
  1231. 'styles' => 'css',
  1232. 'scripts' => 'js',
  1233. 'scripts_bottom' => 'js-bottom',
  1234. 'head' => 'head',
  1235. ];
  1236. $variables['placeholder_token'] = Crypt::randomBytesBase64(55);
  1237. foreach ($types as $type => $placeholder_name) {
  1238. $placeholder = '<' . $placeholder_name . '-placeholder token="' . $variables['placeholder_token'] . '">';
  1239. $variables['#attached']['html_response_attachment_placeholders'][$type] = $placeholder;
  1240. }
  1241. }
  1242. /**
  1243. * Prepares variables for the page template.
  1244. *
  1245. * Default template: page.html.twig.
  1246. *
  1247. * See the page.html.twig template for the list of variables.
  1248. */
  1249. function template_preprocess_page(&$variables) {
  1250. $language_interface = \Drupal::languageManager()->getCurrentLanguage();
  1251. foreach (\Drupal::theme()->getActiveTheme()->getRegions() as $region) {
  1252. if (!isset($variables['page'][$region])) {
  1253. $variables['page'][$region] = [];
  1254. }
  1255. }
  1256. $variables['base_path'] = base_path();
  1257. $variables['front_page'] = \Drupal::url('<front>');
  1258. $variables['language'] = $language_interface;
  1259. // An exception might be thrown.
  1260. try {
  1261. $variables['is_front'] = \Drupal::service('path.matcher')->isFrontPage();
  1262. }
  1263. catch (Exception $e) {
  1264. // If the database is not yet available, set default values for these
  1265. // variables.
  1266. $variables['is_front'] = FALSE;
  1267. $variables['db_is_active'] = FALSE;
  1268. }
  1269. if ($node = \Drupal::routeMatch()->getParameter('node')) {
  1270. $variables['node'] = $node;
  1271. }
  1272. }
  1273. /**
  1274. * Generate an array of suggestions from path arguments.
  1275. *
  1276. * This is typically called for adding to the suggestions in
  1277. * hook_theme_suggestions_HOOK_alter() or adding to 'attributes' class key
  1278. * variables from within preprocess functions, when wanting to base the
  1279. * additional suggestions or classes on the path of the current page.
  1280. *
  1281. * @param $args
  1282. * An array of path arguments.
  1283. * @param $base
  1284. * A string identifying the base 'thing' from which more specific suggestions
  1285. * are derived. For example, 'page' or 'html'.
  1286. * @param $delimiter
  1287. * The string used to delimit increasingly specific information. The default
  1288. * of '__' is appropriate for theme hook suggestions. '-' is appropriate for
  1289. * extra classes.
  1290. *
  1291. * @return
  1292. * An array of suggestions, suitable for adding to
  1293. * hook_theme_suggestions_HOOK_alter() or to $variables['attributes']['class']
  1294. * if the suggestions represent extra CSS classes.
  1295. */
  1296. function theme_get_suggestions($args, $base, $delimiter = '__') {
  1297. // Build a list of suggested theme hooks in order of
  1298. // specificity. One suggestion is made for every element of the current path,
  1299. // though numeric elements are not carried to subsequent suggestions. For
  1300. // example, for $base='page', http://www.example.com/node/1/edit would result
  1301. // in the following suggestions:
  1302. //
  1303. // page__node
  1304. // page__node__%
  1305. // page__node__1
  1306. // page__node__edit
  1307. $suggestions = [];
  1308. $prefix = $base;
  1309. foreach ($args as $arg) {
  1310. // Remove slashes or null per SA-CORE-2009-003 and change - (hyphen) to _
  1311. // (underscore).
  1312. //
  1313. // When we discover templates in @see drupal_find_theme_templates,
  1314. // hyphens (-) are converted to underscores (_) before the theme hook
  1315. // is registered. We do this because the hyphens used for delimiters
  1316. // in hook suggestions cannot be used in the function names of the
  1317. // associated preprocess functions. Any page templates designed to be used
  1318. // on paths that contain a hyphen are also registered with these hyphens
  1319. // converted to underscores so here we must convert any hyphens in path
  1320. // arguments to underscores here before fetching theme hook suggestions
  1321. // to ensure the templates are appropriately recognized.
  1322. $arg = str_replace(["/", "\\", "\0", '-'], ['', '', '', '_'], $arg);
  1323. // The percent acts as a wildcard for numeric arguments since
  1324. // asterisks are not valid filename characters on many filesystems.
  1325. if (is_numeric($arg)) {
  1326. $suggestions[] = $prefix . $delimiter . '%';
  1327. }
  1328. $suggestions[] = $prefix . $delimiter . $arg;
  1329. if (!is_numeric($arg)) {
  1330. $prefix .= $delimiter . $arg;
  1331. }
  1332. }
  1333. if (\Drupal::service('path.matcher')->isFrontPage()) {
  1334. // Front templates should be based on root only, not prefixed arguments.
  1335. $suggestions[] = $base . $delimiter . 'front';
  1336. }
  1337. return $suggestions;
  1338. }
  1339. /**
  1340. * Prepares variables for maintenance page templates.
  1341. *
  1342. * Default template: maintenance-page.html.twig.
  1343. *
  1344. * @param array $variables
  1345. * An associative array containing:
  1346. * - content - An array of page content.
  1347. *
  1348. * @see system_page_attachments()
  1349. */
  1350. function template_preprocess_maintenance_page(&$variables) {
  1351. // @todo Rename the templates to page--maintenance + page--install.
  1352. template_preprocess_page($variables);
  1353. // @see system_page_attachments()
  1354. $variables['#attached']['library'][] = 'system/maintenance';
  1355. // Maintenance page and install page need branding info in variables because
  1356. // there is no blocks.
  1357. $site_config = \Drupal::config('system.site');
  1358. $variables['logo'] = theme_get_setting('logo.url');
  1359. $variables['site_name'] = $site_config->get('name');
  1360. $variables['site_slogan'] = $site_config->get('slogan');
  1361. // Maintenance page and install page need page title in variable because there
  1362. // are no blocks.
  1363. $variables['title'] = $variables['page']['#title'];
  1364. }
  1365. /**
  1366. * Prepares variables for install page templates.
  1367. *
  1368. * Default template: install-page.html.twig.
  1369. *
  1370. * @param array $variables
  1371. * An associative array containing:
  1372. * - content - An array of page content.
  1373. *
  1374. * @see template_preprocess_maintenance_page()
  1375. */
  1376. function template_preprocess_install_page(&$variables) {
  1377. template_preprocess_maintenance_page($variables);
  1378. // Override the site name that is displayed on the page, since Drupal is
  1379. // still in the process of being installed.
  1380. $distribution_name = drupal_install_profile_distribution_name();
  1381. $variables['site_name'] = $distribution_name;
  1382. $variables['site_version'] = drupal_install_profile_distribution_version();
  1383. }
  1384. /**
  1385. * Prepares variables for region templates.
  1386. *
  1387. * Default template: region.html.twig.
  1388. *
  1389. * Prepares the values passed to the theme_region function to be passed into a
  1390. * pluggable template engine. Uses the region name to generate a template file
  1391. * suggestions.
  1392. *
  1393. * @param array $variables
  1394. * An associative array containing:
  1395. * - elements: An associative array containing properties of the region.
  1396. */
  1397. function template_preprocess_region(&$variables) {
  1398. // Create the $content variable that templates expect.
  1399. $variables['content'] = $variables['elements']['#children'];
  1400. $variables['region'] = $variables['elements']['#region'];
  1401. }
  1402. /**
  1403. * Prepares variables for field templates.
  1404. *
  1405. * Default template: field.html.twig.
  1406. *
  1407. * @param array $variables
  1408. * An associative array containing:
  1409. * - element: A render element representing the field.
  1410. * - attributes: A string containing the attributes for the wrapping div.
  1411. * - title_attributes: A string containing the attributes for the title.
  1412. */
  1413. function template_preprocess_field(&$variables, $hook) {
  1414. $element = $variables['element'];
  1415. // Creating variables for the template.
  1416. $variables['entity_type'] = $element['#entity_type'];
  1417. $variables['field_name'] = $element['#field_name'];
  1418. $variables['field_type'] = $element['#field_type'];
  1419. $variables['label_display'] = $element['#label_display'];
  1420. $variables['label_hidden'] = ($element['#label_display'] == 'hidden');
  1421. // Always set the field label - allow themes to decide whether to display it.
  1422. // In addition the label should be rendered but hidden to support screen
  1423. // readers.
  1424. $variables['label'] = $element['#title'];
  1425. $variables['multiple'] = $element['#is_multiple'];
  1426. static $default_attributes;
  1427. if (!isset($default_attributes)) {
  1428. $default_attributes = new Attribute();
  1429. }
  1430. // Merge attributes when a single-value field has a hidden label.
  1431. if ($element['#label_display'] == 'hidden' && !$variables['multiple'] && !empty($element['#items'][0]->_attributes)) {
  1432. $variables['attributes'] = NestedArray::mergeDeep($variables['attributes'], (array) $element['#items'][0]->_attributes);
  1433. }
  1434. // We want other preprocess functions and the theme implementation to have
  1435. // fast access to the field item render arrays. The item render array keys
  1436. // (deltas) should always be numerically indexed starting from 0, and looping
  1437. // on those keys is faster than calling Element::children() or looping on all
  1438. // keys within $element, since that requires traversal of all element
  1439. // properties.
  1440. $variables['items'] = [];
  1441. $delta = 0;
  1442. while (!empty($element[$delta])) {
  1443. $variables['items'][$delta]['content'] = $element[$delta];
  1444. // Modules (e.g., rdf.module) can add field item attributes (to
  1445. // $item->_attributes) within hook_entity_prepare_view(). Some field
  1446. // formatters move those attributes into some nested formatter-specific
  1447. // element in order have them rendered on the desired HTML element (e.g., on
  1448. // the <a> element of a field item being rendered as a link). Other field
  1449. // formatters leave them within $element['#items'][$delta]['_attributes'] to
  1450. // be rendered on the item wrappers provided by field.html.twig.
  1451. $variables['items'][$delta]['attributes'] = !empty($element['#items'][$delta]->_attributes) ? new Attribute($element['#items'][$delta]->_attributes) : clone($default_attributes);
  1452. $delta++;
  1453. }
  1454. }
  1455. /**
  1456. * Prepares variables for individual form element templates.
  1457. *
  1458. * Default template: field-multiple-value-form.html.twig.
  1459. *
  1460. * Combines multiple values into a table with drag-n-drop reordering.
  1461. *
  1462. * @param array $variables
  1463. * An associative array containing:
  1464. * - element: A render element representing the form element.
  1465. */
  1466. function template_preprocess_field_multiple_value_form(&$variables) {
  1467. $element = $variables['element'];
  1468. $variables['multiple'] = $element['#cardinality_multiple'];
  1469. if ($variables['multiple']) {
  1470. $table_id = Html::getUniqueId($element['#field_name'] . '_values');
  1471. $order_class = $element['#field_name'] . '-delta-order';
  1472. $header_attributes = new Attribute(['class' => ['label']]);
  1473. if (!empty($element['#required'])) {
  1474. $header_attributes['class'][] = 'js-form-required';
  1475. $header_attributes['class'][] = 'form-required';
  1476. }
  1477. $header = [
  1478. [
  1479. 'data' => [
  1480. '#prefix' => '<h4' . $header_attributes . '>',
  1481. '#markup' => $element['#title'],
  1482. '#suffix' => '</h4>',
  1483. ],
  1484. 'colspan' => 2,
  1485. 'class' => ['field-label'],
  1486. ],
  1487. t('Order', [], ['context' => 'Sort order']),
  1488. ];
  1489. $rows = [];
  1490. // Sort items according to '_weight' (needed when the form comes back after
  1491. // preview or failed validation).
  1492. $items = [];
  1493. $variables['button'] = [];
  1494. foreach (Element::children($element) as $key) {
  1495. if ($key === 'add_more') {
  1496. $variables['button'] = &$element[$key];
  1497. }
  1498. else {
  1499. $items[] = &$element[$key];
  1500. }
  1501. }
  1502. usort($items, '_field_multiple_value_form_sort_helper');
  1503. // Add the items as table rows.
  1504. foreach ($items as $item) {
  1505. $item['_weight']['#attributes']['class'] = [$order_class];
  1506. // Remove weight form element from item render array so it can be rendered
  1507. // in a separate table column.
  1508. $delta_element = $item['_weight'];
  1509. unset($item['_weight']);
  1510. $cells = [
  1511. ['data' => '', 'class' => ['field-multiple-drag']],
  1512. ['data' => $item],
  1513. ['data' => $delta_element, 'class' => ['delta-order']],
  1514. ];
  1515. $rows[] = [
  1516. 'data' => $cells,
  1517. 'class' => ['draggable'],
  1518. ];
  1519. }
  1520. $variables['table'] = [
  1521. '#type' => 'table',
  1522. '#header' => $header,
  1523. '#rows' => $rows,
  1524. '#attributes' => [
  1525. 'id' => $table_id,
  1526. 'class' => ['field-multiple-table'],
  1527. ],
  1528. '#tabledrag' => [
  1529. [
  1530. 'action' => 'order',
  1531. 'relationship' => 'sibling',
  1532. 'group' => $order_class,
  1533. ],
  1534. ],
  1535. ];
  1536. if (!empty($element['#description'])) {
  1537. $description_id = $element['#attributes']['aria-describedby'];
  1538. $description_attributes['id'] = $description_id;
  1539. $variables['description']['attributes'] = new Attribute($description_attributes);
  1540. $variables['description']['content'] = $element['#description'];
  1541. // Add the description's id to the table aria attributes.
  1542. $variables['table']['#attributes']['aria-describedby'] = $element['#attributes']['aria-describedby'];
  1543. }
  1544. }
  1545. else {
  1546. $variables['elements'] = [];
  1547. foreach (Element::children($element) as $key) {
  1548. $variables['elements'][] = $element[$key];
  1549. }
  1550. }
  1551. }
  1552. /**
  1553. * Prepares variables for breadcrumb templates.
  1554. *
  1555. * Default template: breadcrumb.html.twig.
  1556. *
  1557. * @param array $variables
  1558. * An associative array containing:
  1559. * - links: A list of \Drupal\Core\Link objects which should be rendered.
  1560. */
  1561. function template_preprocess_breadcrumb(&$variables) {
  1562. $variables['breadcrumb'] = [];
  1563. /** @var \Drupal\Core\Link $link */
  1564. foreach ($variables['links'] as $key => $link) {
  1565. $variables['breadcrumb'][$key] = ['text' => $link->getText(), 'url' => $link->getUrl()->toString()];
  1566. }
  1567. }
  1568. /**
  1569. * Callback for usort() within template_preprocess_field_multiple_value_form().
  1570. *
  1571. * Sorts using ['_weight']['#value']
  1572. */
  1573. function _field_multiple_value_form_sort_helper($a, $b) {
  1574. $a_weight = (is_array($a) && isset($a['_weight']['#value']) ? $a['_weight']['#value'] : 0);
  1575. $b_weight = (is_array($b) && isset($b['_weight']['#value']) ? $b['_weight']['#value'] : 0);
  1576. return $a_weight - $b_weight;
  1577. }
  1578. /**
  1579. * Provides theme registration for themes across .inc files.
  1580. */
  1581. function drupal_common_theme() {
  1582. return [
  1583. // From theme.inc.
  1584. 'html' => [
  1585. 'render element' => 'html',
  1586. ],
  1587. 'page' => [
  1588. 'render element' => 'page',
  1589. ],
  1590. 'page_title' => [
  1591. 'variables' => ['title' => NULL],
  1592. ],
  1593. 'region' => [
  1594. 'render element' => 'elements',
  1595. ],
  1596. 'time' => [
  1597. 'variables' => ['timestamp' => NULL, 'text' => NULL, 'attributes' => []],
  1598. ],
  1599. 'datetime_form' => [
  1600. 'render element' => 'element',
  1601. ],
  1602. 'datetime_wrapper' => [
  1603. 'render element' => 'element',
  1604. ],
  1605. 'status_messages' => [
  1606. 'variables' => ['status_headings' => [], 'message_list' => NULL],
  1607. ],
  1608. 'links' => [
  1609. 'variables' => ['links' => [], 'attributes' => ['class' => ['links']], 'heading' => [], 'set_active_class' => FALSE],
  1610. ],
  1611. 'dropbutton_wrapper' => [
  1612. 'variables' => ['children' => NULL],
  1613. ],
  1614. 'image' => [
  1615. // HTML 4 and XHTML 1.0 always require an alt attribute. The HTML 5 draft
  1616. // allows the alt attribute to be omitted in some cases. Therefore,
  1617. // default the alt attribute to an empty string, but allow code providing
  1618. // variables to image.html.twig templates to pass explicit NULL for it to
  1619. // be omitted. Usually, neither omission nor an empty string satisfies
  1620. // accessibility requirements, so it is strongly encouraged for code
  1621. // building variables for image.html.twig templates to pass a meaningful
  1622. // value for the alt variable.
  1623. // - http://www.w3.org/TR/REC-html40/struct/objects.html#h-13.8
  1624. // - http://www.w3.org/TR/xhtml1/dtds.html
  1625. // - http://dev.w3.org/html5/spec/Overview.html#alt
  1626. // The title attribute is optional in all cases, so it is omitted by
  1627. // default.
  1628. 'variables' => ['uri' => NULL, 'width' => NULL, 'height' => NULL, 'alt' => '', 'title' => NULL, 'attributes' => [], 'sizes' => NULL, 'srcset' => [], 'style_name' => NULL],
  1629. ],
  1630. 'breadcrumb' => [
  1631. 'variables' => ['links' => []],
  1632. ],
  1633. 'table' => [
  1634. 'variables' => ['header' => NULL, 'rows' => NULL, 'footer' => NULL, 'attributes' => [], 'caption' => NULL, 'colgroups' => [], 'sticky' => FALSE, 'responsive' => TRUE, 'empty' => ''],
  1635. ],
  1636. 'tablesort_indicator' => [
  1637. 'variables' => ['style' => NULL],
  1638. ],
  1639. 'mark' => [
  1640. 'variables' => ['status' => MARK_NEW],
  1641. ],
  1642. 'item_list' => [
  1643. 'variables' => ['items' => [], 'title' => '', 'list_type' => 'ul', 'wrapper_attributes' => [], 'attributes' => [], 'empty' => NULL, 'context' => []],
  1644. ],
  1645. 'feed_icon' => [
  1646. 'variables' => ['url' => NULL, 'title' => NULL],
  1647. ],
  1648. 'progress_bar' => [
  1649. 'variables' => ['label' => NULL, 'percent' => NULL, 'message' => NULL],
  1650. ],
  1651. 'indentation' => [
  1652. 'variables' => ['size' => 1],
  1653. ],
  1654. // From theme.maintenance.inc.
  1655. 'maintenance_page' => [
  1656. 'render element' => 'page',
  1657. ],
  1658. 'install_page' => [
  1659. 'render element' => 'page',
  1660. ],
  1661. 'maintenance_task_list' => [
  1662. 'variables' => ['items' => NULL, 'active' => NULL, 'variant' => NULL],
  1663. ],
  1664. 'authorize_report' => [
  1665. 'variables' => ['messages' => [], 'attributes' => []],
  1666. 'includes' => ['core/includes/theme.maintenance.inc'],
  1667. 'template' => 'authorize-report',
  1668. ],
  1669. // From pager.inc.
  1670. 'pager' => [
  1671. 'render element' => 'pager',
  1672. ],
  1673. // From menu.inc.
  1674. 'menu' => [
  1675. 'variables' => ['menu_name' => NULL, 'items' => [], 'attributes' => []],
  1676. ],
  1677. 'menu_local_task' => [
  1678. 'render element' => 'element',
  1679. ],
  1680. 'menu_local_action' => [
  1681. 'render element' => 'element',
  1682. ],
  1683. 'menu_local_tasks' => [
  1684. 'variables' => ['primary' => [], 'secondary' => []],
  1685. ],
  1686. // From form.inc.
  1687. 'input' => [
  1688. 'render element' => 'element',
  1689. ],
  1690. 'select' => [
  1691. 'render element' => 'element',
  1692. ],
  1693. 'fieldset' => [
  1694. 'render element' => 'element',
  1695. ],
  1696. 'details' => [
  1697. 'render element' => 'element',
  1698. ],
  1699. 'radios' => [
  1700. 'render element' => 'element',
  1701. ],
  1702. 'checkboxes' => [
  1703. 'render element' => 'element',
  1704. ],
  1705. 'form' => [
  1706. 'render element' => 'element',
  1707. ],
  1708. 'textarea' => [
  1709. 'render element' => 'element',
  1710. ],
  1711. 'form_element' => [
  1712. 'render element' => 'element',
  1713. ],
  1714. 'form_element_label' => [
  1715. 'render element' => 'element',
  1716. ],
  1717. 'vertical_tabs' => [
  1718. 'render element' => 'element',
  1719. ],
  1720. 'container' => [
  1721. 'render element' => 'element',
  1722. ],
  1723. // From field system.
  1724. 'field' => [
  1725. 'render element' => 'element',
  1726. ],
  1727. 'field_multiple_value_form' => [
  1728. 'render element' => 'element',
  1729. ],
  1730. ];
  1731. }