span { width: 5px; height: 5px; background-color: #5b5b5b; } EOL; /** @var FeaturesController */ private $features_controller; /** * @param FeaturesController $features_controller */ public function __construct( FeaturesController $features_controller = null ) { if ($features_controller === null) { $features_controller = ContainerWrapper::getInstance()->get(FeaturesController::class); } $this->features_controller = $features_controller; } public function getDefaultStyles() { if ($this->features_controller->isSupported(FeaturesController::NEW_FORM_EDITOR)) { $text_input_width = 'width: 100%;'; $label_font_weight = 'font-weight: normal;'; } else { $text_input_width = 'width: 200px;'; $label_font_weight = 'font-weight: bold;'; } $styles = str_replace('[TEXT_INPUTS_WIDTH_RULE]', $text_input_width, $this->default_styles); $styles = str_replace('[LABELS_FONT_WEIGHT_RULE]', $label_font_weight, $styles); return $styles; } public function render($stylesheet, $prefix = '') { if (!$stylesheet) return; $styles = new CSSParser($stylesheet); $styles = $styles->parse(); $formatted_styles = []; foreach ($styles->getAllDeclarationBlocks() as $style_declaration) { $selectors = array_map(function($selector) use ($prefix) { return sprintf('%s %s', $prefix, $selector->__toString()); }, $style_declaration->getSelectors()); $selectors = implode(', ', $selectors); $rules = array_map(function($rule) { return $rule->__toString(); }, $style_declaration->getRules()); $rules = sprintf('{ %s }', implode(' ', $rules)); $formatted_styles[] = sprintf('%s %s', $selectors, $rules); } return implode(PHP_EOL, $formatted_styles); } }