Wednesday, 17 March 2021

How to make a text unreadable using CSS?

Imagine you are working on a page where you want to blur a text to make it unreadable for Anonymous users.

Please see the example below in the image:


This is achievable using CSS:

.class-name {

 text-shadow: 7px 7px 7px #0000;

 color: transparent;

}

That's it. All elements with class class-name will blur to become unreadable.

Drupal 8 Blocks: Visibility Hide/Show for certain Roles.

 In Drupal 8, while showing any block, there are visibility settings where, we can select which pages the block can be visible.

The same form has an underlying functionality to hide the block for the selected list or URLs.

Unfortunately, the same is not the case of Roles.

You can select which roles you want to display the block, but, you cannot select which Roles you want to hide the block.

Following code adds a Negate condition to Roles Visibility:


/* Negate the condition to decide visibility of which user roles to show/hide. */

function YOUR_MODULE_form_block_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {

$form['visibility']['user_role']['negate'] = [

'#type' => 'radios',

                '#title' => '',

'#default_value' => 0,

'#options' => [

t('Show for selected Roles'),

t('Hide for selected Roles'),

],

];

}

This adds two radio buttons under the form: Roles.

Following is the screen shot for the same:



Thursday, 4 March 2021

Attention GitHub users: Git will add Token Authentication on August 13, 2021, only Username and Password authentication will not work.

Recently, Github has added strict measures to proivde additional security to its users.

As a major step in this, github is making a Token based authentication mandatory for all Github users from August 13, 2021.

So, mere Username and Password authentication will not work.

Tokens will be generated either for devices or session.

Read in details here

Thursday, 30 May 2019

How to restrict a menu in Drupal 7

Sometimes, we need to restrict a user from accessing a certain page.

You can do it through: hook_menu_alter()

So, if your module name is hello_world, the function should be:

function hello_world_menu_alter(&$items) {
 $items['user/%/edit']['access callback'] = FALSE;
}

Here, we have restricted user from editing profile.

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...