This is to basically add a wrapper to the icon if necessary to achieve specific styling configurations like fancy icon only headers, etc.

Icon Block wrapper example

Comments

kyletaylored’s picture

Status: Active » Needs review
StatusFileSize
new2.67 KB

Patch attached.

markhalliwell’s picture

Title: Add wrapper/classes for Icon Block » Allow icons to be wrapped
Status: Needs review » Needs work

Overall, I generally like the idea :) I do think it needs a little bit of work though to make it more robust:

  1. +++ b/modules/icon_block/icon_block.module
    @@ -38,6 +40,7 @@ function icon_block_preprocess_block(&$variables) {
         if ($icon = theme('icon', array('bundle' => $settings['bundle'], 'icon' => $settings['icon']))) {
    +      $icon = _icon_block_class_wrapper($icon, $settings['wrapper'], $settings['wrapper_class']);
    
    @@ -119,3 +145,15 @@ function icon_block_form_submit($form, &$form_state) {
    + * Helper function for wrapping icons.
    + */
    +function _icon_block_class_wrapper($string, $element = '', $class = '') {
    

    Helper functions are only really ever useful if it helps to reduce duplicitous code or one can see the potential of it being used very often. In this particular case though, I would suspect that it's only ever going to be used in this one spot. The code should just be moved to where it's being implemented.

    I would like to take this a step further though and argue that we shouldn't look at wrapping just the icon_block module. I could see this being something that many people would want to/could use in all of them.

    Perhaps we should, instead, look at generalizing this as a wrapper inside the theme_icon() function itself and extending the form/element settings to include this as a whole.

  2. +++ b/modules/icon_block/icon_block.module
    @@ -100,6 +103,29 @@ function icon_block_form_alter(&$form, &$form_state, $form_id) {
    +      //'#states' => $icon_state,
    

    If not used, remove.

  3. +++ b/modules/icon_block/icon_block.module
    @@ -100,6 +103,29 @@ function icon_block_form_alter(&$form, &$form_state, $form_id) {
    +      '#size' => 60, ¶
    +      '#maxlength' => 128, ¶
    

    Whitespace.

  4. +++ b/modules/icon_block/icon_block.module
    @@ -119,3 +145,15 @@ function icon_block_form_submit($form, &$form_state) {
    +    return '<'.$element.' class="'.$class.'">'.$string.'</'.$element.'>';
    

    Generally speaking, avoid markup like this. Use render arrays; this is the future of D8. Using render arrays allows elements to be preprocessed and avoids things being "set in stone" on the front-end. In this particular example it should have probably looked something more like:

    $build = array(
      '#theme' => 'html_tag__icon_wrapper',
      '#tag' => $element,
      '#value' => $string,
    );
    if (!empty($class)) {
      $build['#attributes']['class'] = explode(' ', $class);
    }
    return drupal_render($build);
    

  • markcarver committed 218153a on 7.x-1.x
    Issue #2311285 by markcarver, kyletaylored: Allow icons to be wrapped
    
markhalliwell’s picture

Status: Needs work » Fixed
StatusFileSize
new18.46 KB

I made the wrapper/wrapper class variables part of the icon theme hook itself. I also moved the configuration to the icon_selector element so it shows up on all forms now.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.