You are here

class PaddingModifier in Modifiers Pack 8

Provides a Modifier to set the padding on an element.

Plugin annotation


@Modifier(
  id = "padding_modifier",
  label = @Translation("Padding Modifier"),
  description = @Translation("Provides a Modifier to set the padding on an element."),
)

Hierarchy

  • class \Drupal\modifiers_padding\Plugin\modifiers\PaddingModifier extends \Drupal\modifiers\ModifierPluginBase

Expanded class hierarchy of PaddingModifier

1 file declares its use of PaddingModifier
PaddingModifierTest.php in modules/modifiers_padding/tests/src/Unit/PaddingModifierTest.php

File

modules/modifiers_padding/src/Plugin/modifiers/PaddingModifier.php, line 17

Namespace

Drupal\modifiers_padding\Plugin\modifiers
View source
class PaddingModifier extends ModifierPluginBase {

  /**
   * {@inheritdoc}
   */
  public static function modification($selector, array $config) {
    $media = parent::getMediaQuery($config);
    if (!empty($config['padding_t_size']) && !empty($config['padding_t_units'])) {
      $css[$media][$selector][] = 'padding-top:' . $config['padding_t_size'] . $config['padding_t_units'];
    }
    if (!empty($config['padding_r_size']) && !empty($config['padding_r_units'])) {
      $css[$media][$selector][] = 'padding-right:' . $config['padding_r_size'] . $config['padding_r_units'];
    }
    if (!empty($config['padding_b_size']) && !empty($config['padding_b_units'])) {
      $css[$media][$selector][] = 'padding-bottom:' . $config['padding_b_size'] . $config['padding_b_units'];
    }
    if (!empty($config['padding_l_size']) && !empty($config['padding_l_units'])) {
      $css[$media][$selector][] = 'padding-left:' . $config['padding_l_size'] . $config['padding_l_units'];
    }
    if (!empty($css)) {
      return new Modification($css);
    }
    return NULL;
  }

}

Members