backdrop-contrib / uc_minicart

Provides a minimal Ubercart shopping cart block.
GNU General Public License v2.0
0 stars 0 forks source link

Remove dependency on Font Awesome, use core Icon API #2

Open laryn opened 1 week ago

laryn commented 1 week ago

At this point it would be good to remove the Font Awesome dependency and bundle some SVG icons (or use core icons if they exist), using the core Icon API.

nattywebdev commented 10 hours ago

@laryn The display of the icons at present is done by building $block_content, which contains (briefly):

<div>
  <i class="fas fa-shopping-cart" title="View cart"></i> <span class="num-items">1</span> item 
  <i class="fas fa-credit-card" title="Checkout"></i>
</div>

whereas the suggested method to add a core icon, eg, a cart, would be:

<?php print icon('shopping-cart'); ?>

according to https://docs.backdropcms.org/documentation/icon-api

Is there a different way to display the icon consistent with the current method? Or does this require a rather different way to build the output for $block_content?

laryn commented 8 hours ago

You could start by testing just replacing the <i class="fas fa-shopping-cart" title="View cart"></i> portion with the new core icon code, and likewise for the credit card icon. Let me know if that works or not.

nattywebdev commented 6 hours ago

I have this working now in my clone of the module (I called it 'uc_minibasket and have it as a custom module).

The module shows just the basket icon and a small number when there's content in the basket (cart).

This is the code that replaced the fontawesome themed output:

      if($item_count > 0){
        $block_content .= l(icon('basket', array('attributes' => array('class' => array('basket'),'alt' => t('View basket')))) . $item_text , 'cart', array('html' => TRUE));
      }else{
        $block_content .= icon('basket', array('attributes' => array('class' => array('basket-empty'),'alt' => t('Basket is empty'))));
      }

and it produces this for the contents of .block-content for an empty basket: image

This shows the resulting html: image

and this for a non-empty basket: image

and here's the html: image

The colouring and position of the basket content quantity are dealt with by css.

Is this any use to you @laryn ?

laryn commented 5 hours ago

Yes, we can definitely use this concept in the module and remove the dependency on Font Awesome. 👍