getData(); $role = 'span'; if (preg_match('/^([A-Za-z-]*)\(([A-Za-z-]*)\)$/', trim($name), $match) === 1) { $name = $match[1]; $role = $match[2]; } $baseRole = $blockContext->getDocumentParserContext()->getTextRoleFactoryForDocument()->getTextRole($role); if (!$baseRole instanceof BaseTextRole) { $this->logger->error( sprintf('Text role "%s", class %s cannot be extended. ', $role, $baseRole::class), $blockContext->getLoggerInformation(), ); return; } $customRole = $baseRole->withName($name); if (is_string($directive->getOption('class')->getValue())) { $customRole->setClass($directive->getOption('class')->getValue()); } else { $customRole->setClass($name); } if ($customRole instanceof GenericTextRole) { $customRole->setBaseRole($role); } $blockContext->getDocumentParserContext()->getTextRoleFactoryForDocument()->replaceTextRole($customRole); } }