Skip to content
Snippets Groups Projects

Fixed Drupal calls.

Merged Chaitanya Dessai requested to merge issue/content_snippets-3436387:2.x into 2.x
2 files
+ 70
3
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 41
2
@@ -6,12 +6,51 @@ use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Messenger\MessengerInterface;
/**
* Delete a Custom Text Snippet.
*/
class SnippetDelete extends ConfigFormBase {
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* Class constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
*/
public function __construct(ConfigFactoryInterface $config_factory, MessengerInterface $messenger) {
$this->configFactory = $config_factory;
$this->messenger = $messenger;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('messenger')
);
}
/**
* Returns a unique string identifying the form.
*
@@ -77,7 +116,7 @@ class SnippetDelete extends ConfigFormBase {
]),
'#description' => $this->t('Before deleting this snippet, it is recommended that you search your site codebase to ensure the machine name is not in use anywhere.'),
];
$content = \Drupal::config('content_snippets.content')->get($snip_id);
$content = $this->configFactory->get('content_snippets.content')->get($snip_id);
$form['content'] = [
'#prefix' => '<br /><h3>Current Content:</h3>',
@@ -105,7 +144,7 @@ class SnippetDelete extends ConfigFormBase {
$items->clear($snip_id);
$items->save();
$form_state->setRedirect('content_snippets.config.snippets_config');
\Drupal::messenger()->addMessage("$snip_id deleted.");
$this->messenger->addMessage("$snip_id deleted.");
parent::submitForm($form, $form_state);
}
Loading