Commit 8f036ac6 authored by osman's avatar osman Committed by osman

Issue #2987391 by osman: Remove `Enable on image fields attached to fieldable...

Issue #2987391 by osman: Remove `Enable on image fields attached to fieldable entities` setting. Issue #2984346 by osman: PHP < 5.5 lacks of `boolval()`  which causes WSOD when saving settings. Issue #2987404 by osman: Library wouldn not be enabled for some users. Issue #2987402 by osman: Uninstalling Lazy.module does not revert the image field display formatters.
parent 19b80962
......@@ -34,15 +34,6 @@ function lazy_configuration_form($form, $form_state) {
'#disabled' => !$filter_enabled,
);
$form['settings']['lazy_filter_image_fields'] = array(
'#type' => 'checkbox',
'#title' => t('Enable on image fields attached to fieldable entities. For example, content-types, blocks.'),
'#description' => t('<div style="color: red;">This setting is disabled and will be removed on next release.<br><br>Now lazy-loading can be enabled for each field separataly via display settings.</div>'),
'#default_value' => variable_get('lazy_filter_image_fields', $defaults['lazy_filter_image_fields']),
'#return_value' => TRUE,
'#disabled' => TRUE,
);
$form['settings']['lazy_filter_placeholderSrc'] = array(
'#type' => 'textfield',
'#title' => t('Placeholder image URL'),
......@@ -176,7 +167,7 @@ function lazy_configuration_form_submit($form, &$form_state) {
$value = intval($value);
}
if (in_array($key, $bool_value)) {
$value = boolval($value);
$value = !!$value;
}
if ('string' === gettype($value)) {
$value = trim($value);
......
......@@ -21,7 +21,6 @@ function lazy_install() {
'lazy_filter_successClass' => 'b-loaded',
'lazy_filter_validateDelay' => 25,
'lazy_filter_placeholderSrc' => 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==',
'lazy_filter_image_fields' => FALSE,
'lazy_disabled_paths' => 'rss.xml',
);
......@@ -70,6 +69,42 @@ function lazy_uninstall() {
->condition('module', $module)
->condition('name', $name)
->execute();
// Revert image field formatters back to `image`.
$lazy_enabled_fields = array();
$field_map = field_info_field_map();
$i = 1;
$max_messages = 10;
foreach ($field_map as $field_name => $field) {
if ($field['type'] === 'image') {
foreach ($field['bundles'] as $entity_type => $bundle) {
$field_instance = field_info_instance($entity_type, $field_name, $bundle[0]);
foreach ($field_instance['display'] as $display_name => $display) {
if ($field_instance['display'][$display_name]['module'] === 'lazy') {
$field_instance['display'][$display_name]['type'] = 'image';
$field_instance['display'][$display_name]['module'] = 'image';
field_update_instance($field_instance);
if ($i <= $max_messages) {
drupal_set_message(t('The %label (<code>!field_name</code>) field in %bundle (!entity_type) type is reverted back in the %display display mode.', array(
'%label' => $field_instance['label'],
'!field_name' => $field_instance['field_name'],
'%bundle' => $field_instance['bundle'],
'!entity_type' => $field_instance['entity_type'],
'%display' => $display_name,
)),
'warning',
TRUE
);
}
$i++;
}
}
}
}
}
if ($i > $max_messages) {
drupal_set_message(t('Also reverted back %no other image fields.', array('%no' => $i - $max_messages)));
}
}
/**
......@@ -157,7 +192,6 @@ function lazy_update_7102() {
function lazy_update_7103() {
$image_fields = variable_get('lazy_filter_image_fields');
if ($image_fields) {
$fields = array();
$field_map = field_info_field_map();
foreach ($field_map as $field_name => $field) {
if ($field['type'] === 'image') {
......
......@@ -95,7 +95,6 @@ function _filter_lazy_defaults() {
'lazy_filter_successClass' => variable_get('lazy_filter_successClass'),
'lazy_filter_validateDelay' => variable_get('lazy_filter_validateDelay'),
'lazy_filter_placeholderSrc' => variable_get('lazy_filter_placeholderSrc'),
'lazy_filter_image_fields' => variable_get('lazy_filter_image_fields'),
);
}
......@@ -173,6 +172,32 @@ function lazy_is_filter_enabled() {
return count($enabled_formats) ? TRUE : FALSE;
}
/**
* Is any of the image fields using the `Lazy-load image` formatter?
*/
function lazy_is_field_enabled() {
$lazy_enabled_fields = array();
$field_map = field_info_field_map();
foreach ($field_map as $field_name => $field) {
if ($field['type'] === 'image') {
foreach ($field['bundles'] as $entity_type => $bundle) {
$field_instance = field_info_instance($entity_type, $field_name, $bundle[0]);
foreach ($field_instance['display'] as $display_name => $display) {
if ($field_instance['display'][$display_name]['type'] === 'lazy') {
$lazy_enabled_fields[] = implode('-', array(
$field_instance['entity_type'],
$field_instance['field_name'],
$display_name,
));
}
}
}
}
}
return !!count($lazy_enabled_fields);
}
/**
* Is Blazy library installed.
*/
......@@ -188,7 +213,7 @@ function lazy_is_library_installed() {
*/
function lazy_page_build(&$page) {
$filter_enabled = lazy_is_filter_enabled();
$field_enabled = variable_get('lazy_filter_image_fields');
$field_enabled = lazy_is_field_enabled();
$library_installed = variable_get('lazy_library_installed');
if ($library_installed) {
......@@ -457,14 +482,10 @@ function theme_lazy_image($variables) {
// Skip Blazy rendering if...
//
// library is not available OR
// viewing a page listed in disabled pages OR
// element has the skip-class added.
// viewing a page listed in disabled pages
if (
!variable_get('lazy_library_installed') ||
in_array(drupal_get_path_alias(), $disabled_paths) || (
!empty($variables['attributes']['class'])
&& in_array($opt_skipClass, $variables['attributes']['class'])
)
in_array(drupal_get_path_alias(), $disabled_paths)
) {
return theme('image', $variables);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment