You are here

class OverrideHelper in Varbase Media 8.5

Same name and namespace in other branches
  1. 8.7 modules/entity_browser_generic_embed/src/OverrideHelper.php \Drupal\entity_browser_generic_embed\OverrideHelper
  2. 8.6 modules/entity_browser_generic_embed/src/OverrideHelper.php \Drupal\entity_browser_generic_embed\OverrideHelper
  3. 9.0.x modules/entity_browser_generic_embed/src/OverrideHelper.php \Drupal\entity_browser_generic_embed\OverrideHelper

Helps tweak and override implementations of various things.

Hierarchy

Expanded class hierarchy of OverrideHelper

3 files declare their use of OverrideHelper
entity_browser_instagram.module in modules/varbase_media_instagram/entity_browser_instagram.module
Support for instagram posts as media entities.
varbase_media.module in ./varbase_media.module
Contains varbase_media.module.
varbase_media_twitter.module in modules/varbase_media_twitter/varbase_media_twitter.module
Support for tweets as media entities.

File

modules/entity_browser_generic_embed/src/OverrideHelper.php, line 10

Namespace

Drupal\entity_browser_generic_embed
View source
class OverrideHelper {

  /**
   * Overrides the class implementation specified in a plugin definition.
   *
   * The replacement class is only used if its immediate parent is the class
   * specified by the plugin definition.
   *
   * @param array $plugin_definition
   *   The plugin definition.
   * @param string $replacement_class
   *   The class to use.
   */
  public static function pluginClass(array &$plugin_definition, $replacement_class) {
    if (get_parent_class($replacement_class) == $plugin_definition['class']) {
      $plugin_definition['class'] = $replacement_class;
    }
  }

  /**
   * Overrides the entity class for an entity type.
   *
   * The replacement class is only used if its immediate parent is the class
   * specified by the entity type.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type definition.
   * @param string $replacement_class
   *   The class to use.
   */
  public static function entityClass(EntityTypeInterface $entity_type, $replacement_class) {
    if (get_parent_class($replacement_class) == $entity_type
      ->getClass()) {
      $entity_type
        ->setClass($replacement_class);
    }
  }

  /**
   * Overrides the class used for an entity form.
   *
   * The replacement class is only used if its immediate parent is the form
   * class used for the specified operation.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type definition.
   * @param string $replacement_class
   *   The class to use.
   * @param string $operation
   *   (optional) The entity operation.
   */
  public static function entityForm(EntityTypeInterface $entity_type, $replacement_class, $operation = 'default') {
    if (get_parent_class($replacement_class) == $entity_type
      ->getFormClass($operation)) {
      $entity_type
        ->setFormClass($operation, $replacement_class);
    }
  }

  /**
   * Overrides the class used for an entity handler.
   *
   * The replacement class is only used if its immediate parent is the handler
   * class specified by the entity type definition.
   *
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
   *   The entity type definition.
   * @param string $handler_type
   *   The handler type.
   * @param string $replacement_class
   *   The class to use.
   */
  public static function entityHandler(EntityTypeInterface $entity_type, $handler_type, $replacement_class) {
    if (get_parent_class($replacement_class) == $entity_type
      ->getHandlerClass($handler_type)) {
      $entity_type
        ->setHandlerClass($handler_type, $replacement_class);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OverrideHelper::entityClass public static function Overrides the entity class for an entity type.
OverrideHelper::entityForm public static function Overrides the class used for an entity form.
OverrideHelper::entityHandler public static function Overrides the class used for an entity handler.
OverrideHelper::pluginClass public static function Overrides the class implementation specified in a plugin definition.