Skip to content
Snippets Groups Projects

Fixed Drupal calls.

1 file
+ 33
4
Compare changes
  • Side-by-side
  • Inline
@@ -2,14 +2,44 @@
namespace Drupal\layout_builder_modal\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Theme\ThemeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides the layout builder modal configuration form.
*/
class LayoutBuilderModalSettingsForm extends ConfigFormBase {
protected $themeConfig;
protected $themeHandler;
/**
* Constructs a LayoutBuilderModalSettingsForm object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
* The theme manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, ThemeManagerInterface $theme_manager) {
parent::__construct($config_factory);
$this->themeConfig = $config_factory->get('system.theme');
$this->themeHandler = $theme_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('theme.manager')
);
}
/**
* {@inheritdoc}
*/
@@ -63,10 +93,9 @@ class LayoutBuilderModalSettingsForm extends ConfigFormBase {
'#default_value' => $config->get('modal_autoresize'),
'#description' => $this->t('Allow modal to automatically resize and enable scrolling for dialog content. If enabled, the ability to drag and resize the dialog will be disabled.'),
];
$theme_config = \Drupal::config('system.theme');
$theme_handler = \Drupal::service('theme_handler');
$theme_config = $this->themeConfig;
$theme_options = [
'default_theme' => $this->t('Default (%default_theme)', ['%default_theme' => $theme_handler->getName($theme_config->get('default'))]),
'default_theme' => $this->t('Default (%default_theme)', ['%default_theme' => $theme_config->get('default')]),
'seven' => $this->t("Administrative (Seven)"),
];
$form['options']['theme_display'] = [
@@ -86,7 +115,7 @@ class LayoutBuilderModalSettingsForm extends ConfigFormBase {
public function validateForm(array &$form, FormStateInterface $form_state) {
$width = $form_state->getValue('modal_width');
if (substr_count($width, '%') == 1 && $width[strlen($width) - 1] == '%') {
$percentage_value = substr($width,0,-1);
$percentage_value = substr($width, 0, -1);
if (!is_numeric($percentage_value) || $percentage_value < 1 || $percentage_value > 100) {
$form_state->setErrorByName('modal_width', $this->t('Width must be a positive number or a percentage.'));
}
Loading