Обернуть таблицу в div
modules/custom/fix/src/Plugin/Filter/TableDiv.php
<?php
namespace Drupal\fix\Plugin\Filter;
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
use Drupal\filter\FilterProcessResult;
use Drupal\filter\Plugin\FilterBase;
/**
* @Filter(
* id = "filter_table_div",
* title = @Translation("Table in a container"),
* description = @Translation("Wrap a table in a div container."),
* type = Drupal\filter\Plugin\FilterInterface::TYPE_MARKUP_LANGUAGE,
* )
*/
class TableDiv extends FilterBase
{
public function process($text, $langcode)
{
$dom = Html::load($text);
$elements = $dom->getElementsByTagName('table');
if ($elements->length === 0) {
return new FilterProcessResult(Html::serialize($dom));
}
/** @var \DOMElement $element */
foreach ($elements as $element) {
$new_element = clone $element;
$wrapper = $dom->createElement('div');
$wrapper->setAttribute('class', 'table-responsive');
$wrapper->setAttribute('style', 'overflow-x:auto;');
$wrapper->appendChild($new_element);
$element->parentNode->replaceChild($wrapper, $element);
}
return new FilterProcessResult(Html::serialize($dom));
}
}