theme.inc 68 KB

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