Hey,

when running Dynamic display block on my development environment with full error reporting on php.ini set:

error_reporting = E_ALL

I get a lot of notices regarding the usage of the _ddblock_get_variable method.
# Notice: Undefined index: pager_container in ddblock_content() (line 1358 of (...)/sites/all/modules/ddblock/ddblock.module).
# Notice: Undefined index: css in ddblock_content() (line 1361 of (...)/sites/all/modules/ddblock/ddblock.module).
# Notice: Undefined index: imgcache_slide in ddblock_content() (line 1368 of (...)/sites/all/modules/ddblock/ddblock.module).

This happens because each call to the method uses nonexistent indexes of the $configuration_settings array as the 1st input parameter. Check the following example:

$pager_container = _ddblock_get_variable($configuration_settings['pager_container'], 'pager-item');

When the 'page_container' index is not set, the notice will be thrown, because PHP processes it when invoking the method. This is easily fixed by operating minor changes on the method implementation, from:

function _ddblock_get_variable($name, $default) {
   return isset($name) ? $name : $default;
}

to

function _ddblock_get_variable($array, $key, $default) {
   return !empty($array[$key]) ? $array[$key] : $default;
}

The subsequent calls to the method would also change from the current scheme:

$pager_container = _ddblock_get_variable($configuration_settings['pager_container'], 'pager-item');

to

$pager_container = _ddblock_get_variable($configuration_settings, 'pager_container', 'pager-item');

I consider this to be a minor improvement, but I think it's a good principle to write clean code that doesn't throw any kind of errors, warnings or notices to the PHP logs.

Comments

ppblaauw’s picture

Thanks for posting, will have a look at this soon.