Skip to content

Commit

Permalink
Further cleanup and add default breakpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
laryn committed Aug 17, 2023
1 parent 7db02b5 commit 09a0346
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 96 deletions.
81 changes: 39 additions & 42 deletions breakpoints.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
function breakpoints_admin_breakpoints($form, &$form_state, $breakpoint_group_name = '') {
$form = array();

// In case of an export to theme, there will be a variable exported_breakpoints
// In case of an export to theme, there will be a variable exported_breakpoints.
if (isset($form_state['exported_breakpoints']) && !empty($form_state['exported_breakpoints'])) {
$form['exported_breakpoints'] = array(
'#title' => t('Copy/Paste the following inside your theme.info file.'),
'#type' => 'textarea',
'#default_value' => $form_state['exported_breakpoints'],
);
}
// Global is the same as no group name
// Global is the same as no group name.
$global = FALSE;
if ($breakpoint_group_name == '' || $breakpoint_group_name == 'global') {
$breakpoint_group_name = '';
Expand Down Expand Up @@ -145,7 +145,7 @@ function breakpoints_admin_breakpoints($form, &$form_state, $breakpoint_group_na
}

if ($global) {
// Add empty row
// Add empty row.
$form['breakpoints']['new'] = array(
'name' => array(
'#type' => 'textfield',
Expand Down Expand Up @@ -188,12 +188,12 @@ function breakpoints_admin_breakpoints($form, &$form_state, $breakpoint_group_na
}
}

// Buttons
// Buttons.
$form['buttons'] = array(
'#type' => 'container',
);

// Submit button
// Submit button.
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
Expand All @@ -218,9 +218,9 @@ function breakpoints_admin_breakpoints($form, &$form_state, $breakpoint_group_na
'#markup' => l(
t('Duplicate group'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/duplicate',
array(
'query' => backdrop_get_destination(),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-duplicate-link')),
)
'query' => backdrop_get_destination(),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-duplicate-link')),
)
),
);
}
Expand All @@ -240,19 +240,19 @@ function breakpoints_admin_breakpoints($form, &$form_state, $breakpoint_group_na
'#markup' => l(
t('Edit group breakpoints'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/edit',
array(
'query' => backdrop_get_destination(),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-edit-link')),
)
'query' => backdrop_get_destination(),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-edit-link')),
)
),
);
$form['buttons']['duplicate'] = array(
'#type' => 'markup',
'#markup' => l(
t('Duplicate group'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/duplicate',
array(
'query' => backdrop_get_destination(),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-duplicate-link')),
)
'query' => backdrop_get_destination(),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-duplicate-link')),
)
),
);
}
Expand All @@ -268,19 +268,19 @@ function breakpoints_admin_breakpoints($form, &$form_state, $breakpoint_group_na
'#markup' => l(
t('Edit group breakpoints'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/edit',
array(
'query' => backdrop_get_destination(),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-edit-link')),
)
'query' => backdrop_get_destination(),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-edit-link')),
)
),
);
$form['buttons']['duplicate'] = array(
'#type' => 'markup',
'#markup' => l(
t('Duplicate group'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/duplicate',
array(
'query' => backdrop_get_destination(),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-duplicate-link')),
)
'query' => backdrop_get_destination(),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-duplicate-link')),
)
),
);
break;
Expand All @@ -295,29 +295,29 @@ function breakpoints_admin_breakpoints($form, &$form_state, $breakpoint_group_na
'#markup' => l(
t('Edit group breakpoints'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/edit',
array(
'query' => backdrop_get_destination(),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-edit-link')),
)
'query' => backdrop_get_destination(),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-edit-link')),
)
),
);
$form['buttons']['duplicate'] = array(
'#type' => 'markup',
'#markup' => l(
t('Duplicate group'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/duplicate',
array(
'query' => backdrop_get_destination(),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-duplicate-link')),
)
'query' => backdrop_get_destination(),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-duplicate-link')),
)
),
);
$form['buttons']['deletelink'] = array(
'#type' => 'markup',
'#markup' => l(
t('Delete this group'), 'admin/config/media/breakpoints/groups/' . $breakpoint_group_name . '/delete',
array(
'query' => array('destination' => 'admin/config/media/breakpoints/groups'),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-delete-link')),
)
'query' => array('destination' => 'admin/config/media/breakpoints/groups'),
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-delete-link')),
)
),
);
break;
Expand Down Expand Up @@ -453,7 +453,7 @@ function breakpoints_admin_breakpoints_submit($form, &$form_state) {
$global_group = $group_name == '';
$group = breakpoints_breakpoint_group_empty_object();
if (!$global_group) {
// sort by weight, needed to store the right order in a group
// Sort by weight, needed to store the right order in a group.
uasort($breakpoints, '_breakpoints_sort_by_weight_array');
}
$saved_breakpoints = array();
Expand All @@ -462,7 +462,7 @@ function breakpoints_admin_breakpoints_submit($form, &$form_state) {
if (!empty($breakpointdata['name'])) {
$breakpoint = breakpoints_breakpoint_load_by_fullkey($breakpointname);
if ($breakpoint && $breakpointname != 'new') {
// only save the weight when on the global screen.
// Only save the weight when on the global screen.
if ($global_group) {
$breakpoint->weight = $breakpointdata['weight'];
}
Expand Down Expand Up @@ -644,7 +644,6 @@ function breakpoints_add_style_form($form, &$form_state) {
'#size' => '64',
'#title' => t('Image style base name'),
'#description' => t('The name is used in URLs for generated images. Use only lowercase alphanumeric characters, underscores (_), and hyphens (-).'),
'#element_validate' => array('image_style_name_validate'),
'#required' => TRUE,
);
$breakpoints = breakpoints_breakpoint_load_all_active();
Expand Down Expand Up @@ -709,14 +708,15 @@ function breakpoints_add_style_form_submit($form, &$form_state) {
foreach (array_filter($form_state['values']['breakpoints']) as $breakpoint) {
$new_style = array(
'name' => $form_state['values']['base_name'] . $breakpoint,
'label' => $base['label'] . ': ' . $breakpoint,
);
$style = image_style_save($new_style);
if ($style) {
foreach ($base['effects'] as $effect) {
$effect['isid'] = $style['isid'];
$effect['data']['style_name'] = $new_style['name'];
unset($effect['ieid']);
image_effect_save($effect);
image_effect_save($new_style['name'], $effect);
}
}
}
Expand Down Expand Up @@ -773,12 +773,12 @@ function breakpoints_admin_breakpoint_group_edit_form($form, &$form_state, $mach
'#required' => TRUE,
);

// Buttons
// Buttons.
$form['buttons'] = array(
'#type' => 'container',
);

// Submit button
// Submit button.
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
Expand Down Expand Up @@ -1044,12 +1044,12 @@ function breakpoints_admin_breakpoint_group_duplicate_form($form, &$form_state,
),
);

// Buttons
// Buttons.
$form['buttons'] = array(
'#type' => 'container',
);

// Submit button
// Submit button.
$form['buttons']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
Expand All @@ -1060,8 +1060,8 @@ function breakpoints_admin_breakpoint_group_duplicate_form($form, &$form_state,
'#markup' => l(
t('Cancel'), 'admin/config/media/breakpoints/groups/' . $src_group->machine_name,
array(
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-cancel-link')),
)
'attributes' => array('class' => array('breakpoints-group-operations-link', 'breakpoints-group-operations-cancel-link')),
)
),
);

Expand All @@ -1082,9 +1082,6 @@ function breakpoints_admin_breakpoint_group_duplicate_form_submit($form, &$form_
$src_group = $form_state['#src_group'];
if ($src_group) {
breakpoints_breakpoints_group_duplicate($src_group, $name, $machine_name);
// Clear the Ctools export API cache.
//ctools_include('export');
//ctools_export_load_object_reset('breakpoint_group');
menu_rebuild();
$form_state['redirect'] = 'admin/config/media/breakpoints/groups/' . $machine_name;
backdrop_set_message(t('The new group have been created'));
Expand Down
14 changes: 14 additions & 0 deletions breakpoints.install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
* Breakpoints
*/

/**
* Implements hook_enable().
* Import breakpoints from all enabled themes.
*/
function breakpoints_enable() {
$themes = list_themes();
foreach ($themes as $theme_key => $theme) {
if (!$theme->status) {
unset($themes[$theme_key]);
}
}
breakpoints_themes_enabled(array_keys($themes));
}

/**
* Implements hook_update_last_removed().
*/
Expand Down
Loading

0 comments on commit 09a0346

Please sign in to comment.