theme.inc 67 KB

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