You are here

class LayoutParagraphsUpdateLayoutSubscriber in Layout Paragraphs 2.0.x

Event subscriber.

Hierarchy

Expanded class hierarchy of LayoutParagraphsUpdateLayoutSubscriber

1 string reference to 'LayoutParagraphsUpdateLayoutSubscriber'
layout_paragraphs.services.yml in ./layout_paragraphs.services.yml
layout_paragraphs.services.yml
1 service uses LayoutParagraphsUpdateLayoutSubscriber
layout_paragraphs_update_layout_subscriber in ./layout_paragraphs.services.yml
\Drupal\layout_paragraphs\EventSubscriber\LayoutParagraphsUpdateLayoutSubscriber

File

src/EventSubscriber/LayoutParagraphsUpdateLayoutSubscriber.php, line 11

Namespace

Drupal\layout_paragraphs\EventSubscriber
View source
class LayoutParagraphsUpdateLayoutSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritDoc}
   */
  public static function getSubscribedEvents() {
    return [
      LayoutParagraphsUpdateLayoutEvent::EVENT_NAME => 'compareLayouts',
    ];
  }

  /**
   * Restricts available types based on settings in layout.
   *
   * @param \Drupal\layout_paragraphs\Event\LayoutParagraphsUpdateLayoutEvent $event
   *   The allowed types event.
   */
  public function compareLayouts(LayoutParagraphsUpdateLayoutEvent $event) {
    $original = $event
      ->getOriginalLayout()
      ->getParagraphsReferenceField();
    $layout = $event
      ->getUpdatedLayout()
      ->getParagraphsReferenceField();
    $event->needsRefresh = $original
      ->isEmpty() != $layout
      ->isEmpty();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LayoutParagraphsUpdateLayoutSubscriber::compareLayouts public function Restricts available types based on settings in layout.
LayoutParagraphsUpdateLayoutSubscriber::getSubscribedEvents public static function