Thursday 28 March 2019

How to flip font awesome icons

Recently came across a problem with font awesome icons.

We are required to show unlock icon. So, we showed it with:

<i class="fa fa-unlock"></i>

And it showed like:





But, we are supposed to show like:



That is, we need to flip the unlock icon.

So, after some research, found solution.

Add class fa-flip-horizontal to <i>

<i class="fa fa-unlock fa-flip-horizontal"></i>

And the unlock icon is flipped.

Tuesday 19 March 2019

Drupal 8 uninstall a module programmatically

Drupal 8 does not allow to enable/disable modules like previous versions.

You have to completely uninstall a module to get rid of it.

You can install the module be:

<?php
  
\Drupal::service('module_installer')->install(['admin_toolbar']);?>



You can uninstall the module by:

<?php
  
\Drupal::service('module_installer')->uninstall(['admin_toolbar']);?>

Monday 18 March 2019

Drupal 8: Get User Profile Field Allowed values list


Say, you have a user profile field: field_phone_brand

And you have options:

iPhone|iPhone
Samsung|Samsung
MI|MI
Oppo|Oppo
Vivo|Vivo

And you want to get the allowed values list in a custom module/theme,

$entityManager = \Drupal::service('entity_field.manager');
$fields = $entityManager->getFieldStorageDefinitions('user', 'profile');
$options options_allowed_values($fields[$fieldName]);

If you print:

echo '<pre>';
print_r($options);
echo '</pre>';

You will get:

Array
(
    [iPhone] => iPhone
    [Samsung] => Samsung
    [MI] => MI
    [Oppo] => Oppo
    [Vivo] => Vivo
)

Parenting tips to inculcate learning habits in your kid

Parenting tips to inculcate learning habits in your kid Tip #1) Children do not learn things, they emitate. So, try to do things by yours...