Skip to content
Snippets Groups Projects

fixed phpcs issues

Closed Jasjeet Brar requested to merge issue/shortcode-3422956:2.0.x into 7.x-2.x
34 files
+ 2754
931
Compare changes
  • Side-by-side
  • Inline
Files
34
<?php
namespace Drupal\shortcode_basic_tags\Plugin\Shortcode;
use Drupal\block_content\Entity\BlockContent;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Render\RendererInterface;
use Drupal\shortcode\Plugin\ShortcodeBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Insert a custom block to the text.
*
* @Shortcode(
* id = "block",
* title = @Translation("Block"),
* description = @Translation("Insert a block.")
* )
*/
class BlockShortcode extends ShortcodeBase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* Constructs a new Shortcode plugin.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin ID for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
RendererInterface $renderer,
EntityTypeManagerInterface $entity_type_manager
) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $renderer);
$this->entityTypeManager = $entity_type_manager;
$this->renderer = $renderer;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('renderer'),
$container->get('entity_type.manager')
);
}
/**
* {@inheritdoc}
*/
public function process(array $attributes, $text, $langcode = Language::LANGCODE_NOT_SPECIFIED) {
// Merge with default attributes.
$attributes = $this->getAttributes([
'id' => '',
'view' => 'full',
],
$attributes
);
if ((int) $attributes['id']) {
$block_entity = BlockContent::load($attributes['id']);
if ($block_entity) {
$block_view = $this->entityTypeManager->getViewBuilder('block_content')->view($block_entity, $attributes['view']);
if ($block_view) {
return $this->renderer->render($block_view);
}
}
}
}
/**
* {@inheritdoc}
*/
public function tips($long = FALSE) {
$output = [];
$output[] = '<p><strong>' . $this->t('[block id="1" (view="full") /]') . '</strong>';
$output[] = $this->t('Inserts a block.') . '</p>';
if ($long) {
$output[] = '<p>' . $this->t('The block display view can be specified using the <em>view</em> parameter.') . '</p>';
}
return implode(' ', $output);
}
}
Loading