LayoutBuilderSortTrait.php

Same filename in other branches
  1. 8.9.x core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderSortTrait.php
  2. 10 core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderSortTrait.php
  3. 11.x core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderSortTrait.php

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

File

core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderSortTrait.php

View source
<?php

namespace Drupal\Tests\layout_builder\FunctionalJavascript;

use Drupal\FunctionalJavascriptTests\SortableTestTrait;

/**
 * LayoutBuilderSortTrait, provides callback for simulated layout change.
 */
trait LayoutBuilderSortTrait {
    use SortableTestTrait;
    
    /**
     * {@inheritdoc}
     */
    protected function sortableUpdate($item, $from, $to = NULL) {
        // If container does not change, $from and $to are equal.
        $to = $to ?: $from;
        $script = <<<JS
(function (src, from, to) {
  var sourceElement = document.querySelector(src);
  var fromElement = document.querySelector(from);
  var toElement = document.querySelector(to);

  Drupal.layoutBuilderBlockUpdate(sourceElement, fromElement, toElement)

})('{<span class="php-variable">$item</span>}', '{<span class="php-variable">$from</span>}', '{<span class="php-variable">$to</span>}')

JS;
        $options = [
            'script' => $script,
            'args' => [],
        ];
        $this->getSession()
            ->getDriver()
            ->getWebDriverSession()
            ->execute($options);
    }

}

Traits

Title Deprecated Summary
LayoutBuilderSortTrait LayoutBuilderSortTrait, provides callback for simulated layout change.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.