breakpoints.admin.inc

Breakpoints - admin settings

Functions

Namesort descending Description
breakpoints_add_style_form
breakpoints_add_style_form_submit
breakpoints_add_style_form_validate
breakpoints_admin_breakpoints Admin form
breakpoints_admin_breakpoints_submit Admin form submit.
breakpoints_admin_breakpoints_submit_exporttotheme Admin form submit - Export breakpoints to theme.
breakpoints_admin_breakpoints_submit_override Admin form submit - Override theme breakpoints.
breakpoints_admin_breakpoints_submit_reload Admin form submit - Reload theme breakpoints.
breakpoints_admin_breakpoints_submit_revert Admin form submit - Revert theme breakpoints.
breakpoints_admin_breakpoints_validate Admin form validation.
breakpoints_admin_breakpoint_actions_form Admin action form: enable, disable, delete, export
breakpoints_admin_breakpoint_actions_form_submit Admin action form submit
breakpoints_admin_breakpoint_actions_page Page callback.
breakpoints_admin_breakpoint_export_form Export a breakpoint.
breakpoints_admin_breakpoint_group_delete_form Delete a group.
breakpoints_admin_breakpoint_group_delete_form_submit Delete a group.
breakpoints_admin_breakpoint_group_duplicate_form Duplicate group form.
breakpoints_admin_breakpoint_group_duplicate_form_submit Duplicate group form submit.
breakpoints_admin_breakpoint_group_duplicate_form_validate Duplicate group form validate.
breakpoints_admin_breakpoint_group_edit_form
breakpoints_admin_breakpoint_group_edit_form_no_breakpoints
breakpoints_admin_breakpoint_group_edit_form_submit
breakpoints_admin_breakpoint_group_edit_form_validate
breakpoints_admin_breakpoint_group_export_form Export a group.
breakpoints_admin_breakpoint_group_import_form Import a breakpoint group.
breakpoints_admin_breakpoint_group_import_form_submit Import breakpoint group.
breakpoints_admin_breakpoint_group_import_form_validate Validate a breakpoint group import.
breakpoints_admin_breakpoint_import_form Import breakpoint.
breakpoints_admin_breakpoint_import_form_submit Import breakpoint.
breakpoints_admin_breakpoint_import_form_validate Validate a breakpoint import.
breakpoints_admin_multiplier_delete_form
breakpoints_admin_multiplier_delete_form_submit
breakpoints_admin_settings_form
breakpoints_multipliers_form Multipliers administration form.
breakpoints_multipliers_form_submit
breakpoints_multipliers_form_validate
theme_breakpoints_admin_breakpoints_table Theme form as table.
theme_breakpoints_multipliers_table_form
_breakpoints_admin_breakpoints_table_new_row Helper callback for theme_breakpoints_admin_breakpoints_table().
_breakpoints_admin_breakpoints_table_row Helper callback for theme_breakpoints_admin_breakpoints_table().

File

sites/all/modules/local_contrib/breakpoints/breakpoints.admin.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Breakpoints - admin settings
  5. */
  6. /**
  7. * Admin form
  8. */
  9. function breakpoints_admin_breakpoints($form, &$form_state, $breakpoint_group_name = '') {
  10. $form = array();
  11. // In case of an export to theme, there will be a variable exported_breakpoints
  12. if (isset($form_state['exported_breakpoints']) && !empty($form_state['exported_breakpoints'])) {
  13. $form['exported_breakpoints'] = array(
  14. '#title' => t('Copy/Paste the following inside your theme.info file.'),
  15. '#type' => 'textarea',
  16. '#default_value' => $form_state['exported_breakpoints'],
  17. );
  18. }
  19. // Global is the same as no group name
  20. $global = FALSE;
  21. if ($breakpoint_group_name == '' || $breakpoint_group_name == 'global') {
  22. $breakpoint_group_name = '';
  23. $global = TRUE;
  24. }
  25. $form_state['group_name'] = $breakpoint_group_name;
  26. $settings = breakpoints_settings();
  27. $multipliers = array();
  28. if (isset($settings->multipliers) && !empty($settings->multipliers)) {
  29. $multipliers = drupal_map_assoc(array_values($settings->multipliers));
  30. if (array_key_exists('1x', $multipliers)) {
  31. unset($multipliers['1x']);
  32. }
  33. }
  34. if ($global) {
  35. $form['info'] = array(
  36. '#type' => 'markup',
  37. '#markup' => t("You can manage all your breakpoints on this screen, if one of your themes has breakpoints defined inside the .info file they will be shown here."),
  38. );
  39. $info = array();
  40. $info[] = t("To create a new breakpoint, you have to enter a name and a media query (ex. (min-width: 15em)).");
  41. $info[] = t("All breakpoints can be enabled or disabled so they cannot be used by other modules.");
  42. $info[] = t("For each breakpoint you can define what multipliers have to be available (needed to support 'retina' displays).");
  43. $info[] = t("Breakpoints you created yourself can be deleted.");
  44. $info[] = t("You can group multiple breakpoints in a group by using '!add', so other modules can easily interact with them.", array('!add' => l(t('Add a new group'), 'admin/config/media/breakpoints/groups/add')));
  45. $form['more_info'] = array(
  46. '#type' => 'container',
  47. '#theme' => 'item_list',
  48. '#items' => $info,
  49. );
  50. }
  51. else {
  52. $form['info'] = array(
  53. '#type' => 'markup',
  54. '#markup' => t("You can manage the breakpoints of this group here."),
  55. );
  56. $info = array();
  57. $info[] = t("You can change the order of the breakpoints inside this group.");
  58. $info[] = t("You can enable multipliers for each breakpoint, but this will also affect other groups.");
  59. $form['more_info'] = array(
  60. '#type' => 'container',
  61. '#theme' => 'item_list',
  62. '#items' => $info,
  63. );
  64. }
  65. $form['#attached']['css'][] = drupal_get_path('module', 'breakpoints') . '/css/breakpoints.admin.css';
  66. $form['breakpoints'] = array(
  67. '#type' => 'container',
  68. '#tree' => TRUE,
  69. '#theme' => 'breakpoints_admin_breakpoints_table',
  70. '#multipliers' => $multipliers,
  71. '#group_name' => $breakpoint_group_name,
  72. );
  73. $breakpoints = array();
  74. $breakpoint_group = breakpoints_breakpoint_group_load($breakpoint_group_name);
  75. if ($global) {
  76. $breakpoints = breakpoints_breakpoint_load_all();
  77. }
  78. else {
  79. $weight = 0;
  80. foreach ($breakpoint_group->breakpoints as $breakpoint_name) {
  81. $breakpoint = breakpoints_breakpoint_load_by_fullkey($breakpoint_name);
  82. if ($breakpoint && isset($breakpoint->machine_name)) {
  83. $breakpoint->global_weight = $breakpoint->weight;
  84. $breakpoint->weight = $weight++;
  85. $breakpoints[$breakpoint_name] = $breakpoint;
  86. }
  87. }
  88. }
  89. foreach ($breakpoints as $key => $breakpoint) {
  90. if ($breakpoint->source_type == BREAKPOINTS_SOURCE_TYPE_THEME) {
  91. $bp_group = breakpoints_breakpoint_group_load($breakpoint->source);
  92. if ($bp_group->overridden && variable_get('breakpoints_hide_overridden_breakpoints', 1) && $global) {
  93. continue;
  94. }
  95. }
  96. $form['breakpoints'][$key] = array(
  97. '#breakpoint_data' => $breakpoint,
  98. 'name' => array(
  99. '#type' => 'textfield',
  100. '#default_value' => $breakpoint->name,
  101. '#disabled' => TRUE,
  102. '#size' => 20,
  103. ),
  104. 'breakpoint' => array(
  105. '#type' => 'textfield',
  106. '#default_value' => $breakpoint->breakpoint,
  107. '#disabled' => $breakpoint->source_type === 'theme' || !$global,
  108. '#size' => empty($multipliers) ? 60 : 30,
  109. '#maxlength' => 255,
  110. ),
  111. 'weight' => array(
  112. '#type' => 'textfield',
  113. '#size' => 4,
  114. '#default_value' => isset($breakpoint->weight) ? $breakpoint->weight : 0,
  115. '#attributes' => array('class' => array('breakpoints-weight')),
  116. ),
  117. );
  118. // Add multipliers checkboxes if needed.
  119. if (!empty($multipliers)) {
  120. $form['breakpoints'][$key]['multipliers'] = array(
  121. '#type' => 'checkboxes',
  122. '#default_value' => (isset($breakpoint->multipliers) && is_array($breakpoint->multipliers)) ? $breakpoint->multipliers : array(),
  123. '#options' => $multipliers,
  124. );
  125. }
  126. // Add global weight if needed.
  127. $form['breakpoints'][$key]['global_weight'] = array(
  128. '#type' => 'value',
  129. '#value' => isset($breakpoint->global_weight) ? $breakpoint->global_weight : $breakpoint->weight,
  130. );
  131. }
  132. if ($global) {
  133. // Add empty row
  134. $form['breakpoints']['new'] = array(
  135. 'name' => array(
  136. '#type' => 'textfield',
  137. '#default_value' => '',
  138. '#size' => 20,
  139. '#maxlength' => 255,
  140. ),
  141. 'machine_name' => array(
  142. '#type' => 'machine_name',
  143. '#size' => '64',
  144. '#title' => t('Machine name'),
  145. '#default_value' => '',
  146. '#machine_name' => array(
  147. 'exists' => 'breakpoints_breakpoint_name_exists',
  148. 'source' => array('breakpoints', 'new', 'name'),
  149. ),
  150. '#required' => FALSE,
  151. '#maxlength' => 255,
  152. ),
  153. 'breakpoint' => array(
  154. '#type' => 'textfield',
  155. '#default_value' => '',
  156. '#size' => empty($multipliers) ? 60 : 30,
  157. '#maxlength' => 255,
  158. ),
  159. 'weight' => array(
  160. '#type' => 'textfield',
  161. '#size' => 4,
  162. '#default_value' => 0,
  163. '#attributes' => array('class' => array('breakpoints-weight')),
  164. ),
  165. );
  166. // Add multipliers checkboxes if needed.
  167. if (!empty($multipliers)) {
  168. $form['breakpoints']['new']['multipliers'] = array(
  169. '#type' => 'checkboxes',
  170. '#default_value' => array(),
  171. '#options' => $multipliers,
  172. );
  173. }
  174. }
  175. // Buttons
  176. $form['buttons'] = array(
  177. '#type' => 'container',
  178. );
  179. // Submit button
  180. $form['buttons']['submit'] = array(
  181. '#type' => 'submit',
  182. '#value' => t('Save'),
  183. );
  184. if (!$global) {
  185. switch ($breakpoint_group->type) {
  186. case BREAKPOINTS_SOURCE_TYPE_THEME:
  187. if (!$breakpoint_group->overridden) {
  188. $form['buttons']['override'] = array(
  189. '#type' => 'submit',
  190. '#value' => t('Override theme breakpoints'),
  191. '#submit' => array('breakpoints_admin_breakpoints_submit_override'),
  192. );
  193. $form['buttons']['reload'] = array(
  194. '#type' => 'submit',
  195. '#value' => t('Reload theme breakpoints'),
  196. '#submit' => array('breakpoints_admin_breakpoints_submit_reload'),
  197. );
  198. $form['buttons']['duplicate'] = array(
  199. '#type' => 'markup',
  200. '#markup' => l(
  201. t('Duplicate group'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/duplicate',
  202. array(
  203. 'query' => drupal_get_destination(),
  204. 'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-duplicate-link')),
  205. )
  206. ),
  207. );
  208. }
  209. else {
  210. $form['buttons']['exporttotheme'] = array(
  211. '#type' => 'submit',
  212. '#value' => t('Export breakpoints to theme'),
  213. '#submit' => array('breakpoints_admin_breakpoints_submit_exporttotheme'),
  214. );
  215. $form['buttons']['revert'] = array(
  216. '#type' => 'submit',
  217. '#value' => t('Revert theme breakpoints'),
  218. '#submit' => array('breakpoints_admin_breakpoints_submit_revert'),
  219. );
  220. $form['buttons']['editlink'] = array(
  221. '#type' => 'markup',
  222. '#markup' => l(
  223. t('Edit group breakpoints'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/edit',
  224. array(
  225. 'query' => drupal_get_destination(),
  226. 'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-edit-link')),
  227. )
  228. ),
  229. );
  230. $form['buttons']['duplicate'] = array(
  231. '#type' => 'markup',
  232. '#markup' => l(
  233. t('Duplicate group'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/duplicate',
  234. array(
  235. 'query' => drupal_get_destination(),
  236. 'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-duplicate-link')),
  237. )
  238. ),
  239. );
  240. }
  241. break;
  242. case BREAKPOINTS_SOURCE_TYPE_MODULE:
  243. $form['buttons']['exporttotheme'] = array(
  244. '#type' => 'submit',
  245. '#value' => t('Export breakpoints to theme'),
  246. '#submit' => array('breakpoints_admin_breakpoints_submit_exporttotheme'),
  247. );
  248. $form['buttons']['editlink'] = array(
  249. '#type' => 'markup',
  250. '#markup' => l(
  251. t('Edit group breakpoints'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/edit',
  252. array(
  253. 'query' => drupal_get_destination(),
  254. 'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-edit-link')),
  255. )
  256. ),
  257. );
  258. $form['buttons']['duplicate'] = array(
  259. '#type' => 'markup',
  260. '#markup' => l(
  261. t('Duplicate group'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/duplicate',
  262. array(
  263. 'query' => drupal_get_destination(),
  264. 'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-duplicate-link')),
  265. )
  266. ),
  267. );
  268. break;
  269. case BREAKPOINTS_SOURCE_TYPE_CUSTOM:
  270. $form['buttons']['exporttotheme'] = array(
  271. '#type' => 'submit',
  272. '#value' => t('Export breakpoints to theme'),
  273. '#submit' => array('breakpoints_admin_breakpoints_submit_exporttotheme'),
  274. );
  275. $form['buttons']['editlink'] = array(
  276. '#type' => 'markup',
  277. '#markup' => l(
  278. t('Edit group breakpoints'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/edit',
  279. array(
  280. 'query' => drupal_get_destination(),
  281. 'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-edit-link')),
  282. )
  283. ),
  284. );
  285. $form['buttons']['duplicate'] = array(
  286. '#type' => 'markup',
  287. '#markup' => l(
  288. t('Duplicate group'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/duplicate',
  289. array(
  290. 'query' => drupal_get_destination(),
  291. 'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-duplicate-link')),
  292. )
  293. ),
  294. );
  295. $form['buttons']['deletelink'] = array(
  296. '#type' => 'markup',
  297. '#markup' => l(
  298. t('Delete this group'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/delete',
  299. array(
  300. 'query' => array('destination' => 'admin/config/media/breakpoints/groups'),
  301. 'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-delete-link')),
  302. )
  303. ),
  304. );
  305. break;
  306. }
  307. }
  308. return $form;
  309. }
  310. /**
  311. * Theme form as table.
  312. */
  313. function theme_breakpoints_admin_breakpoints_table($variables) {
  314. drupal_add_css(drupal_get_path('module', 'breakpoints') . '/css/breakpoints.admin.css');
  315. $form = $variables['form'];
  316. $global = empty($form['#group_name']);
  317. // Rows.
  318. $rows = array();
  319. foreach (element_children($form) as $key) {
  320. if ($key != 'new') {
  321. $row = _breakpoints_admin_breakpoints_table_row($form[$key], $key, $global);
  322. $breakpoint = $form[$key]['#breakpoint_data'];
  323. $class = 'breakpoints-status-' . ($breakpoint->status ? 'enabled' : 'disabled');
  324. }
  325. else {
  326. $row = _breakpoints_admin_breakpoints_table_new_row($form[$key]);
  327. $class = 'breakpoints-status-new';
  328. }
  329. $rows[] = array(
  330. 'data' => $row,
  331. 'class' => array('draggable', $class),
  332. );
  333. }
  334. // Header.
  335. $header = array();
  336. $header[] = array('data' => t('Name'), 'colspan' => 2);
  337. $header[] = t('Breakpoint, @media ...');
  338. $header[] = t('Multipliers');
  339. $header[] = t('Source');
  340. $header[] = t('Status');
  341. if ($global) {
  342. $header[] = array('data' => t('Operations'), 'colspan' => 3);
  343. }
  344. $header[] = t('Weight');
  345. $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'resp-img-breakpoints')));
  346. drupal_add_tabledrag('resp-img-breakpoints', 'order', 'sibling', 'breakpoints-weight');
  347. return $output;
  348. }
  349. /**
  350. * Helper callback for theme_breakpoints_admin_breakpoints_table().
  351. */
  352. function _breakpoints_admin_breakpoints_table_row(&$element, $key, $global) {
  353. $row = array();
  354. $link_attributes = array(
  355. 'attributes' => array(
  356. 'class' => array('image-style-link'),
  357. ),
  358. );
  359. $breakpoint = $element['#breakpoint_data'];
  360. $element['weight']['#attributes']['class'] = array('breakpoints-weight');
  361. $row[] = drupal_render($element['name']);
  362. $row[] = '';
  363. $row[] = drupal_render($element['breakpoint']);
  364. $row[] = drupal_render($element['multipliers']);
  365. $row[] = $breakpoint->source . ' (' . $breakpoint->source_type . ')';
  366. $row[] = $breakpoint->status ? t('Enabled') : t('Disabled');
  367. if ($global) {
  368. $row[] = l($breakpoint->status ? t('Disable') : t('Enable'), 'admin/config/media/breakpoints/' . ($breakpoint->status ? 'disable' : 'enable') . '/' . $key, $link_attributes);
  369. $row[] = $breakpoint->source_type == BREAKPOINTS_SOURCE_TYPE_CUSTOM ? l(t('Delete'), 'admin/config/media/breakpoints/delete/' . $key, $link_attributes) : '';
  370. $row[] = l(t('Export'), 'admin/config/media/breakpoints/export/' . $key, $link_attributes);
  371. }
  372. $row[] = drupal_render($element['weight']);
  373. return $row;
  374. }
  375. /**
  376. * Helper callback for theme_breakpoints_admin_breakpoints_table().
  377. */
  378. function _breakpoints_admin_breakpoints_table_new_row(&$element) {
  379. $row = array();
  380. $row[] = drupal_render($element['name']);
  381. $row[] = drupal_render($element['machine_name']);
  382. $row[] = drupal_render($element['breakpoint']);
  383. $row[] = drupal_render($element['multipliers']);
  384. $row[] = '';
  385. $row[] = '';
  386. $row[] = '';
  387. $row[] = '';
  388. $row[] = '';
  389. $row[] = drupal_render($element['weight']);
  390. return $row;
  391. }
  392. /**
  393. * Admin form validation.
  394. */
  395. function breakpoints_admin_breakpoints_validate($form, &$form_state) {
  396. if (strpos($form_state['triggering_element']['#id'], 'remove') === FALSE) {
  397. $breakpoints = $form_state['values']['breakpoints'];
  398. if (!empty($breakpoints)) {
  399. foreach ($breakpoints as $key => $breakpointdata) {
  400. if (!empty($breakpointdata['name'])) {
  401. // Breakpoint is required.
  402. if ($key == 'new') {
  403. if (empty($breakpointdata['machine_name'])) {
  404. form_set_error('breakpoints][' . $key . '][machine_name', 'Machine name field is required');
  405. }
  406. }
  407. if (empty($breakpointdata['breakpoint']) && $breakpointdata['breakpoint'] !== '0') {
  408. form_set_error('breakpoints][' . $key . '][breakpoint', 'Breakpoint field is required');
  409. }
  410. }
  411. }
  412. }
  413. }
  414. }
  415. /**
  416. * Admin form submit.
  417. */
  418. function breakpoints_admin_breakpoints_submit($form, &$form_state) {
  419. $breakpoints = $form_state['values']['breakpoints'];
  420. $group_name = $form_state['group_name'];
  421. $global_group = $group_name == '';
  422. $group = breakpoints_breakpoint_group_empty_object();
  423. if (!$global_group) {
  424. // sort by weight, needed to store the right order in a group
  425. uasort($breakpoints, '_breakpoints_sort_by_weight_array');
  426. }
  427. $saved_breakpoints = array();
  428. if (!empty($breakpoints)) {
  429. foreach ($breakpoints as $breakpointname => $breakpointdata) {
  430. if (!empty($breakpointdata['name'])) {
  431. $breakpoint = breakpoints_breakpoint_load_by_fullkey($breakpointname);
  432. if ($breakpoint && $breakpointname != 'new') {
  433. // only save the weight when on the global screen.
  434. if ($global_group) {
  435. $breakpoint->weight = $breakpointdata['weight'];
  436. }
  437. else {
  438. $breakpoint->weight = $breakpointdata['global_weight'];
  439. }
  440. $breakpoint->breakpoint = $breakpointdata['breakpoint'];
  441. $breakpoint->multipliers = $breakpointdata['multipliers'];
  442. breakpoints_breakpoint_save($breakpoint);
  443. $saved_breakpoints[] = $breakpointname;
  444. }
  445. else {
  446. $breakpoint = new stdClass();
  447. $breakpoint->name = $breakpointdata['name'];
  448. $breakpoint->breakpoint = $breakpointdata['breakpoint'];
  449. $breakpoint->source = 'user';
  450. $breakpoint->source_type = 'custom';
  451. $breakpoint->weight = $breakpointdata['weight'];
  452. $breakpoint->status = TRUE;
  453. $breakpoint->multipliers = $breakpointdata['multipliers'];
  454. $breakpoint->machine_name = 'custom.user.' . $breakpointdata['machine_name'];
  455. breakpoints_breakpoint_save($breakpoint);
  456. $saved_breakpoints[] = breakpoints_breakpoint_config_name($breakpoint);
  457. }
  458. }
  459. }
  460. if (!$global_group) {
  461. $group = breakpoints_breakpoint_group_load($group_name);
  462. if ($group) {
  463. $group->breakpoints = $saved_breakpoints;
  464. breakpoints_breakpoint_group_save($group);
  465. }
  466. }
  467. }
  468. }
  469. /**
  470. * Admin form submit - Override theme breakpoints.
  471. */
  472. function breakpoints_admin_breakpoints_submit_override($form, &$form_state) {
  473. $group_name = $form_state['group_name'];
  474. $group = breakpoints_breakpoint_group_empty_object();
  475. $global_group = $group_name == '';
  476. if (!$global_group) {
  477. $group = breakpoints_breakpoint_group_load($group_name);
  478. if ($group) {
  479. breakpoints_breakpoints_group_override($group);
  480. }
  481. }
  482. }
  483. /**
  484. * Admin form submit - Revert theme breakpoints.
  485. */
  486. function breakpoints_admin_breakpoints_submit_revert($form, &$form_state) {
  487. $group_name = $form_state['group_name'];
  488. $global_group = $group_name == '';
  489. if (!$global_group) {
  490. $group = breakpoints_breakpoint_group_load($group_name);
  491. if ($group) {
  492. breakpoints_breakpoints_group_revert($group);
  493. }
  494. }
  495. }
  496. /**
  497. * Admin form submit - Reload theme breakpoints.
  498. */
  499. function breakpoints_admin_breakpoints_submit_reload($form, &$form_state) {
  500. $group_name = $form_state['group_name'];
  501. $global_group = $group_name == '';
  502. if (!$global_group) {
  503. $group = breakpoints_breakpoint_group_load($group_name);
  504. if ($group) {
  505. breakpoints_breakpoints_group_reload($group);
  506. }
  507. }
  508. }
  509. /**
  510. * Admin form submit - Export breakpoints to theme.
  511. */
  512. function breakpoints_admin_breakpoints_submit_exporttotheme($form, &$form_state) {
  513. $group_name = $form_state['group_name'];
  514. $global_group = $group_name == '';
  515. if (!$global_group) {
  516. $group = breakpoints_breakpoint_group_load($group_name);
  517. if ($group) {
  518. $breakpoints = breakpoints_breakpoints_group_exporttotheme($group);
  519. if ($breakpoints) {
  520. $export = array();
  521. foreach ($breakpoints as $breakpoint_name => $breakpoint) {
  522. $export[] = 'breakpoints[' . $breakpoint_name . '] = ' . $breakpoint;
  523. }
  524. $form_state['exported_breakpoints'] = implode("\n", $export);
  525. $form_state['rebuild'] = TRUE;
  526. }
  527. }
  528. }
  529. }
  530. /**
  531. * Page callback.
  532. */
  533. function breakpoints_admin_breakpoint_actions_page($group_name, $action, $breakpoint) {
  534. if (in_array($action, array('enable', 'disable', 'delete', 'export'))) {
  535. return drupal_get_form('breakpoints_admin_breakpoint_actions_form', $group_name, $action, $breakpoint);
  536. }
  537. return MENU_NOT_FOUND;
  538. }
  539. /**
  540. * Admin action form: enable, disable, delete, export
  541. */
  542. function breakpoints_admin_breakpoint_actions_form($form, &$form_state, $group_name, $action, $breakpoint) {
  543. switch ($action) {
  544. case 'enable':
  545. case 'disable':
  546. case 'delete':
  547. $form_state['group_name'] = $group_name;
  548. $form_state['action'] = $action;
  549. $form_state['breakpoint'] = $breakpoint;
  550. $question = t('Are you sure you want to %action %breakpoint', array(
  551. '%action' => $action,
  552. '%breakpoint' => $breakpoint,
  553. ));
  554. if (!empty($group_name)) {
  555. $path = 'admin/config/media/breakpoints/groups/' . $group_name;
  556. }
  557. else {
  558. $path = 'admin/config/media/breakpoints';
  559. }
  560. $form = confirm_form($form, $question, $path, '');
  561. break;
  562. case 'export':
  563. $form = drupal_get_form('breakpoints_admin_breakpoint_export_form', $breakpoint);
  564. break;
  565. }
  566. return $form;
  567. }
  568. /**
  569. * Admin action form submit
  570. */
  571. function breakpoints_admin_breakpoint_actions_form_submit($form, &$form_state) {
  572. $group_name = $form_state['group_name'];
  573. $action = $form_state['action'];
  574. $breakpoint = $form_state['breakpoint'];
  575. switch ($action) {
  576. case 'delete':
  577. breakpoints_breakpoint_delete_by_fullkey($breakpoint);
  578. break;
  579. case 'enable':
  580. case 'disable':
  581. breakpoints_breakpoint_toggle_status($breakpoint);
  582. break;
  583. }
  584. if (!empty($group_name)) {
  585. $form_state['redirect'] = 'admin/config/media/breakpoints/groups/' . $group_name;
  586. }
  587. else {
  588. $form_state['redirect'] = 'admin/config/media/breakpoints';
  589. }
  590. }
  591. function breakpoints_add_style_form($form, &$form_state) {
  592. module_load_include('inc', 'image', 'image.admin');
  593. $form['style'] = array(
  594. '#title' => t('Image style'),
  595. '#type' => 'select',
  596. '#options' => array_filter(image_style_options(FALSE), '_breakpoints_filter_styles'),
  597. '#required' => TRUE,
  598. '#description' => t('This image style will be cloned to create the responsive style'),
  599. );
  600. $form['base_name'] = array(
  601. '#type' => 'textfield',
  602. '#size' => '64',
  603. '#title' => t('Image style base name'),
  604. '#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
  605. '#element_validate' => array('image_style_name_validate'),
  606. '#required' => TRUE,
  607. );
  608. $breakpoints = breakpoints_breakpoint_load_all_active();
  609. if (isset($breakpoints) && !empty($breakpoints)) {
  610. $options = array();
  611. foreach ($breakpoints as $breakpoint) {
  612. foreach ($breakpoint->multipliers as $multiplier) {
  613. $options[str_replace('.', '_', $breakpoint->machine_name . '_' . $multiplier)] = $breakpoint->name . ' [' . $breakpoint->breakpoint . ', multiplier:' . $multiplier . ']';
  614. }
  615. }
  616. $form['breakpoints'] = array(
  617. '#title' => t('breakpoints'),
  618. '#type' => 'checkboxes',
  619. '#options' => $options,
  620. '#default_value' => drupal_map_assoc(array_keys($options)),
  621. '#description' => t('Select the breakpoints to create an image style for'),
  622. '#required' => TRUE,
  623. );
  624. $form['submit'] = array(
  625. '#type' => 'submit',
  626. '#value' => t('Create'),
  627. );
  628. }
  629. else {
  630. $form['redirect_link'] = array(
  631. '#markup' => t("You need to create a breakpoint first before creating a responsive style. ") . l('Click here', 'admin/config/media/breakpoints') . t(" to continue with configuring breakpoints."),
  632. );
  633. }
  634. return $form;
  635. }
  636. function breakpoints_add_style_form_validate($form, &$form_state) {
  637. foreach (array_filter($form_state['values']['breakpoints']) as $breakpoint) {
  638. if (image_style_load($form_state['values']['base_name'] . $breakpoint)) {
  639. form_set_error('breakpoints', t('An image style with the name !name already exists', array('!name' => $form_state['values']['base_name'] . $breakpoint)));
  640. }
  641. }
  642. }
  643. function breakpoints_add_style_form_submit($form, &$form_state) {
  644. $base = image_style_load($form_state['values']['style']);
  645. if (!isset($base['effects'])) {
  646. $base['effects'] = array();
  647. }
  648. foreach (array_filter($form_state['values']['breakpoints']) as $breakpoint) {
  649. $new_style = array(
  650. 'name' => $form_state['values']['base_name'] . $breakpoint,
  651. );
  652. $style = image_style_save($new_style);
  653. if ($style) {
  654. foreach ($base['effects'] as $effect) {
  655. $effect['isid'] = $style['isid'];
  656. unset($effect['ieid']);
  657. image_effect_save($effect);
  658. }
  659. }
  660. }
  661. $form_state['redirect'] = 'admin/config/media/image-styles';
  662. drupal_set_message(t('The new styles have been created'));
  663. }
  664. function breakpoints_admin_breakpoint_group_edit_form($form, &$form_state, $machine_name = '') {
  665. $form = array();
  666. $group = breakpoints_breakpoint_group_load($machine_name);
  667. $breakpoints = breakpoints_breakpoint_load_all();
  668. if (empty($breakpoints)) {
  669. return breakpoints_admin_breakpoint_group_edit_form_no_breakpoints();
  670. }
  671. $form_state['#breakpoint_group'] = $group;
  672. $is_new = $machine_name == '';
  673. $form_state['#is_new'] = $is_new;
  674. $form['name'] = array(
  675. '#type' => 'textfield',
  676. '#size' => '64',
  677. '#title' => t('group name'),
  678. '#required' => TRUE,
  679. '#default_value' => isset($group->name) ? $group->name : '',
  680. '#disabled' => !$is_new,
  681. );
  682. $form['machine_name'] = array(
  683. '#type' => 'machine_name',
  684. '#size' => '64',
  685. '#title' => t('Machine name'),
  686. '#required' => TRUE,
  687. '#default_value' => isset($group->machine_name) ? $group->machine_name : '',
  688. '#disabled' => !$is_new,
  689. '#machine_name' => array(
  690. 'exists' => 'breakpoints_breakpoint_group_name_exists',
  691. ),
  692. );
  693. foreach ($breakpoints as $breakpoint_name => $breakpoint) {
  694. $options[$breakpoint_name] = $breakpoint->name . ' [' . $breakpoint->breakpoint . ']';
  695. }
  696. $form['breakpoints'] = array(
  697. '#title' => 'Select the breakpoints you want to use in this group',
  698. '#type' => 'checkboxes',
  699. '#options' => $options,
  700. '#default_value' => isset($group->breakpoints) ? drupal_map_assoc($group->breakpoints) : array(),
  701. '#required' => TRUE,
  702. );
  703. // Buttons
  704. $form['buttons'] = array(
  705. '#type' => 'container',
  706. );
  707. // Submit button
  708. $form['buttons']['submit'] = array(
  709. '#type' => 'submit',
  710. '#value' => t('Save'),
  711. );
  712. if (!$is_new && $group->type == BREAKPOINTS_SOURCE_TYPE_CUSTOM) {
  713. $form['buttons']['deletelink'] = array(
  714. '#type' => 'markup',
  715. '#markup' => l(t('Delete this group'), 'admin/config/media/breakpoints/groups/' . $group->machine_name . '/delete', array(
  716. 'query' => drupal_get_destination(),
  717. )),
  718. );
  719. }
  720. return $form;
  721. }
  722. function breakpoints_admin_breakpoint_group_edit_form_no_breakpoints() {
  723. $form = array();
  724. $form['info'] = array(
  725. '#type' => 'markup',
  726. '#markup' => t("There're no breakpoints defined, you'll have to !create them first.", array('!create' => l(t('create'), 'admin/config/media/breakpoints'))),
  727. );
  728. return $form;
  729. }
  730. function breakpoints_admin_breakpoint_group_edit_form_validate($form, &$form_state) {
  731. $name = $form_state['values']['machine_name'];
  732. $label = $form_state['values']['name'];
  733. }
  734. function breakpoints_admin_breakpoint_group_edit_form_submit($form, &$form_state) {
  735. $machine_name = $form_state['values']['machine_name'];
  736. $name = $form_state['values']['name'];
  737. $breakpoints = array();
  738. foreach ($form_state['values']['breakpoints'] as $breakpoint => $status) {
  739. if ($status) {
  740. $breakpoints[] = $breakpoint;
  741. }
  742. }
  743. $is_new = $form_state['#is_new'];
  744. if ($is_new) {
  745. $new_group = breakpoints_breakpoint_group_empty_object();
  746. $new_group->machine_name = $machine_name;
  747. $new_group->name = $name;
  748. $new_group->type = BREAKPOINTS_SOURCE_TYPE_CUSTOM;
  749. $new_group->breakpoints = $breakpoints;
  750. breakpoints_breakpoint_group_save($new_group);
  751. menu_rebuild();
  752. $form_state['redirect'] = 'admin/config/media/breakpoints/groups/' . $machine_name;
  753. drupal_set_message(t('The new group have been created'));
  754. }
  755. else {
  756. $existing_group = breakpoints_breakpoint_group_load($machine_name);
  757. $existing_group->breakpoints = $breakpoints;
  758. breakpoints_breakpoint_group_save($existing_group);
  759. }
  760. }
  761. /**
  762. * Delete a group.
  763. */
  764. function breakpoints_admin_breakpoint_group_delete_form($form, &$form_state, $machine_name) {
  765. $group = breakpoints_breakpoint_group_load($machine_name);
  766. $form_state['machine_name'] = $machine_name;
  767. $question = t('Are you sure you want to delete %group', array(
  768. '%group' => $group->name,
  769. ));
  770. $path = 'admin/config/media/breakpoints/groups';
  771. return confirm_form($form, $question, $path, '');
  772. }
  773. /**
  774. * Delete a group.
  775. */
  776. function breakpoints_admin_breakpoint_group_delete_form_submit($form, &$form_state) {
  777. $machine_name = $form_state['machine_name'];
  778. breakpoints_breakpoint_group_delete_by_name($machine_name);
  779. menu_rebuild();
  780. $form_state['redirect'] = 'admin/config/media/breakpoints';
  781. }
  782. /**
  783. * Export a group.
  784. */
  785. function breakpoints_admin_breakpoint_group_export_form($form, &$form_state, $machine_name) {
  786. // Create the export code textarea.
  787. ctools_include('export');
  788. $group = breakpoints_breakpoint_group_load($machine_name);
  789. if (!$group || !$machine_name) {
  790. $group = new stdClass();
  791. }
  792. $group_export = breakpoints_breakpoint_group_export($group);
  793. $form['group_export'] = array(
  794. '#type' => 'textarea',
  795. '#title' => t('Breakpoint group code'),
  796. '#rows' => count(explode("\n", $group_export)),
  797. '#default_value' => $group_export,
  798. );
  799. $breakpoints_export = NULL;
  800. if (isset($group->breakpoints)) {
  801. foreach ($group->breakpoints as $breakpoint) {
  802. if (!is_array($breakpoint) && !is_object($breakpoint)) {
  803. $breakpoint = breakpoints_breakpoint_load_by_fullkey($breakpoint);
  804. }
  805. $breakpoints_export .= ctools_export_object('breakpoints', $breakpoint);
  806. $breakpoints_export .= "\n";
  807. }
  808. }
  809. $form['breakpoints_export'] = array(
  810. '#type' => 'textarea',
  811. '#title' => t('Breakpoints code'),
  812. '#rows' => count(explode("\n", $breakpoints_export)),
  813. '#default_value' => $breakpoints_export,
  814. );
  815. return $form;
  816. }
  817. /**
  818. * Import a breakpoint group.
  819. */
  820. function breakpoints_admin_breakpoint_group_import_form($form, &$form_state) {
  821. $form['import'] = array(
  822. '#type' => 'textarea',
  823. '#rows' => 10,
  824. );
  825. $form['submit'] = array(
  826. '#type' => 'submit',
  827. '#value' => t('Import')
  828. );
  829. return $form;
  830. }
  831. /**
  832. * Validate a breakpoint group import.
  833. */
  834. function breakpoints_admin_breakpoint_group_import_form_validate($form, &$form_state) {
  835. ctools_include('export');
  836. $code = $form_state['values']['import'];
  837. $group = ctools_export_crud_import('breakpoint_group', $code);
  838. if (!breakpoints_breakpoint_group_validate($group)) {
  839. form_set_error('import', t('Not a valid group object'));
  840. return;
  841. }
  842. if (breakpoints_breakpoint_group_name_exists($group->machine_name)) {
  843. form_set_error('import', t('A group with machine name %name already exists', array('%name' => $group->machine_name)));
  844. return;
  845. }
  846. foreach ($group->breakpoints as $key => $breakpoint) {
  847. // check if the breakpoint is a fully loaded object.
  848. if (is_array($breakpoint) || is_object($breakpoint)) {
  849. if (!breakpoints_breakpoint_validate($breakpoint)) {
  850. form_set_error('import', t('The breakpoint group contains an invalid breakpoint.'));
  851. return;
  852. }
  853. }
  854. }
  855. // Manually imported groups are the same as custom made groups.
  856. $group->type = BREAKPOINTS_SOURCE_TYPE_CUSTOM;
  857. form_set_value($form['import'], $group, $form_state);
  858. }
  859. /**
  860. * Import breakpoint group.
  861. */
  862. function breakpoints_admin_breakpoint_group_import_form_submit($form, &$form_state) {
  863. $group = $form_state['values']['import'];
  864. foreach ($group->breakpoints as $key => $breakpoint) {
  865. // check if the breakpoint is a fully loaded object.
  866. if (is_array($breakpoint) || is_object($breakpoint)) {
  867. $breakpoint = (object)$breakpoint;
  868. // If the breakpoints exist, only overwrite the custom ones.
  869. if ($existing_breakpoint = breakpoints_breakpoint_load_by_fullkey($breakpoint->machine_name)) {
  870. if ($breakpoint->source_type == BREAKPOINTS_SOURCE_TYPE_CUSTOM) {
  871. $breakpoint = (object)array_merge((array)$existing_breakpoint, (array)$breakpoint);
  872. breakpoints_breakpoint_save($breakpoint);
  873. }
  874. }
  875. else {
  876. breakpoints_breakpoint_save($breakpoint);
  877. }
  878. $group->breakpoints[$key] = $breakpoint->machine_name;
  879. }
  880. }
  881. if (breakpoints_breakpoint_group_save($group)) {
  882. drupal_set_message(t('Group %group saved.', array('%group' => $group->name)));
  883. $form_state['redirect'] = 'admin/config/media/breakpoints/groups/' . $group->machine_name;
  884. }
  885. else {
  886. drupal_set_message(t('Something went wrong, we could not save the group', 'error'));
  887. }
  888. }
  889. /**
  890. * Export a breakpoint.
  891. */
  892. function breakpoints_admin_breakpoint_export_form($form, $form_state, $fullkey) {
  893. // Create the export code textarea.
  894. ctools_include('export');
  895. $breakpoint = breakpoints_breakpoint_load_by_fullkey($fullkey);
  896. if (!$breakpoint) {
  897. $breakpoint = new stdClass();
  898. }
  899. $export = ctools_export_object('breakpoints', $breakpoint);
  900. $form['export'] = array(
  901. '#type' => 'textarea',
  902. '#title' => t('Breakpoint code'),
  903. '#rows' => 20,
  904. '#default_value' => $export,
  905. );
  906. return $form;
  907. }
  908. /**
  909. * Import breakpoint.
  910. */
  911. function breakpoints_admin_breakpoint_import_form($form, $form_state) {
  912. $form['import'] = array(
  913. '#type' => 'textarea',
  914. '#rows' => 10,
  915. );
  916. $form['submit'] = array(
  917. '#type' => 'submit',
  918. '#value' => t('Import')
  919. );
  920. return $form;
  921. }
  922. /**
  923. * Validate a breakpoint import.
  924. */
  925. function breakpoints_admin_breakpoint_import_form_validate($form, &$form_state) {
  926. ctools_include('export');
  927. $code = $form_state['values']['import'];
  928. $breakpoint = ctools_export_crud_import('breakpoints', $code);
  929. if (!breakpoints_breakpoint_validate($breakpoint)) {
  930. form_set_error('import', t('Not a valid breakpoint object'));
  931. }
  932. else {
  933. if (breakpoints_breakpoint_machine_name_exists($breakpoint->machine_name)) {
  934. form_set_error('import', t('A breakpoint with machine name %name already exists', array('%name' => $breakpoint->machine_name)));
  935. }
  936. else {
  937. form_set_value($form['import'], $breakpoint, $form_state);
  938. }
  939. }
  940. }
  941. /**
  942. * Import breakpoint.
  943. */
  944. function breakpoints_admin_breakpoint_import_form_submit($form, &$form_state) {
  945. $breakpoint = $form_state['values']['import'];
  946. if (breakpoints_breakpoint_save($breakpoint)) {
  947. drupal_set_message(t('Breakpoint %breakpoint saved.', array('%breakpoint' => $breakpoint->name)));
  948. $form_state['redirect'] = 'admin/config/media/breakpoints/';
  949. }
  950. else {
  951. drupal_set_message(t('Something went wrong, we could not save the breakpoint'), 'error');
  952. }
  953. }
  954. /**
  955. * Multipliers administration form.
  956. */
  957. function breakpoints_multipliers_form($form, &$form_state) {
  958. $settings = breakpoints_settings();
  959. $multipliers = drupal_map_assoc($settings->multipliers);
  960. if (isset($multipliers['1x'])) {
  961. unset($multipliers['1x']);
  962. }
  963. $form['multipliers'] = array(
  964. '#type' => 'container',
  965. '#tree' => TRUE,
  966. '#theme' => 'breakpoints_multipliers_table_form',
  967. );
  968. $form['multipliers']['1x'] = array(
  969. '#markup' => '1x',
  970. );
  971. foreach ($multipliers as $multiplier) {
  972. $form['multipliers'][$multiplier] = array(
  973. '#type' => 'textfield',
  974. '#title' => '',
  975. '#required' => FALSE,
  976. '#default_value' => $multiplier,
  977. );
  978. }
  979. $form['multipliers']['new'] = array(
  980. '#type' => 'textfield',
  981. '#title' => '',
  982. '#required' => FALSE,
  983. '#default_value' => '',
  984. '#description' => t('Multiplier like 1.5x, 2x.'),
  985. );
  986. $form['submit'] = array(
  987. '#type' => 'submit',
  988. '#value' => t('Save'),
  989. );
  990. return $form;
  991. }
  992. function theme_breakpoints_multipliers_table_form($element) {
  993. $form = $element['form'];
  994. $header = array(t('Label'), t('Operations'));
  995. foreach (element_children($form) as $multiplier) {
  996. $row = array();
  997. $row[] = drupal_render($form[$multiplier]);
  998. $row[] = in_array($multiplier, array('new', '1x')) ? '' : l(t('Delete'), 'admin/config/media/breakpoints/multipliers/' . $multiplier . '/delete');
  999. $rows[] = $row;
  1000. }
  1001. return theme('table', array('header' => $header, 'rows' => $rows));
  1002. }
  1003. function breakpoints_multipliers_form_validate($form, $form_state) {
  1004. $multipliers = $form_state['values']['multipliers'];
  1005. $saved_multipliers = array(
  1006. '1x' => '1x',
  1007. );
  1008. foreach ($multipliers as $form_key => $multiplier) {
  1009. if ($multiplier == '' && $form_key != 'new') {
  1010. form_set_error('multipliers][' . $form_key, t('Label is required.'));
  1011. }
  1012. if ($multiplier != '') {
  1013. if (isset($saved_multipliers[$multiplier])) {
  1014. form_set_error('multipliers][' . $form_key, t('Label must be unique.'));
  1015. }
  1016. $saved_multipliers[$multiplier] = $multiplier;
  1017. }
  1018. }
  1019. }
  1020. function breakpoints_multipliers_form_submit($form, &$form_state) {
  1021. $multipliers = array_values(array_filter($form_state['values']['multipliers']));
  1022. array_unshift($multipliers, '1x');
  1023. breakpoints_settings_save($multipliers);
  1024. drupal_set_message(t('Multiplier settings are saved.'));
  1025. }
  1026. function breakpoints_admin_multiplier_delete_form($form, &$form_state, $multiplier) {
  1027. $path = 'admin/config/media/breakpoints/multipliers';
  1028. if ($multiplier == '1x') {
  1029. $form['multiplier'] = array(
  1030. '#markup' => t('Multiplier %multiplier can not be deleted! !link', array('%multiplier' => $multiplier, '!link' => l(t('Back to overview page.'), $path)))
  1031. );
  1032. return $form;
  1033. }
  1034. $form['multiplier'] = array(
  1035. '#type' => 'value',
  1036. '#value' => $multiplier,
  1037. );
  1038. return confirm_form($form, t('Are you sure you want to delete multiplier %multiplier', array('%multiplier' => $multiplier)), $path);
  1039. }
  1040. function breakpoints_admin_multiplier_delete_form_submit($form, &$form_state) {
  1041. $settings = breakpoints_settings();
  1042. $multiplier = $form_state['values']['multiplier'];
  1043. $multipliers = drupal_map_assoc($settings->multipliers);
  1044. if (isset($multipliers[$multiplier])) {
  1045. unset($multipliers[$multiplier]);
  1046. }
  1047. breakpoints_settings_save(array_values($multipliers));
  1048. drupal_set_message(t('Multiplier %multiplier was deleted', array('%multiplier' => $multiplier)));
  1049. $form_state['redirect'] = 'admin/config/media/breakpoints/multipliers';
  1050. }
  1051. function breakpoints_admin_settings_form($form, &$form_state) {
  1052. $form['breakpoints_hide_overridden_breakpoints'] = array(
  1053. '#type' => 'checkbox',
  1054. '#description' => t('When overriding breakpoints defined by a theme, hide them on the overview page'),
  1055. '#title' => t('Hide overridden breakpoints'),
  1056. '#default_value' => variable_get('breakpoints_hide_overridden_breakpoints', 1),
  1057. );
  1058. return system_settings_form($form);
  1059. }
  1060. /**
  1061. * Duplicate group form.
  1062. */
  1063. function breakpoints_admin_breakpoint_group_duplicate_form($form, &$form_state, $breakpoint_group_name) {
  1064. $form = array();
  1065. $src_group = breakpoints_breakpoint_group_load($breakpoint_group_name);
  1066. $form_state['#src_group'] = $src_group;
  1067. $form['#attached']['css'][] = drupal_get_path('module', 'breakpoints') . '/css/breakpoints.admin.css';
  1068. $form['name'] = array(
  1069. '#type' => 'textfield',
  1070. '#size' => '64',
  1071. '#title' => t('New group name'),
  1072. '#required' => TRUE,
  1073. '#default_value' => t('Duplicate of') . ' ' . $src_group->name,
  1074. );
  1075. $form['machine_name'] = array(
  1076. '#type' => 'machine_name',
  1077. '#size' => '64',
  1078. '#title' => t('Machine name'),
  1079. '#required' => TRUE,
  1080. '#default_value' => '',
  1081. '#machine_name' => array(
  1082. 'exists' => 'breakpoints_breakpoint_group_name_exists',
  1083. ),
  1084. );
  1085. // Buttons
  1086. $form['buttons'] = array(
  1087. '#type' => 'container',
  1088. );
  1089. // Submit button
  1090. $form['buttons']['submit'] = array(
  1091. '#type' => 'submit',
  1092. '#value' => t('Save'),
  1093. );
  1094. $form['buttons']['cancellink'] = array(
  1095. '#type' => 'markup',
  1096. '#markup' => l(
  1097. t('Cancel'), 'admin/config/media/breakpoints/groups/' . $src_group->machine_name,
  1098. array(
  1099. 'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-cancel-link')),
  1100. )
  1101. ),
  1102. );
  1103. return $form;
  1104. }
  1105. /**
  1106. * Duplicate group form validate.
  1107. */
  1108. function breakpoints_admin_breakpoint_group_duplicate_form_validate($form, &$form_state) {
  1109. }
  1110. /**
  1111. * Duplicate group form submit.
  1112. */
  1113. function breakpoints_admin_breakpoint_group_duplicate_form_submit($form, &$form_state) {
  1114. $machine_name = $form_state['values']['machine_name'];
  1115. $name = $form_state['values']['name'];
  1116. $src_group = $form_state['#src_group'];
  1117. if ($src_group) {
  1118. breakpoints_breakpoints_group_duplicate($src_group, $name, $machine_name);
  1119. // Clear the Ctools export API cache.
  1120. ctools_include('export');
  1121. ctools_export_load_object_reset('breakpoint_group');
  1122. menu_rebuild();
  1123. $form_state['redirect'] = 'admin/config/media/breakpoints/groups/' . $machine_name;
  1124. drupal_set_message(t('The new group have been created'));
  1125. }
  1126. }