class WorkbenchContentController in Workbench 8
Generates the pages defined by Workbench.
Hierarchy
- class \Drupal\Core\Controller\ControllerBase implements ContainerInjectionInterface uses LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\node\Controller\NodeController implements ContainerInjectionInterface
- class \Drupal\workbench\Controller\WorkbenchContentController
- class \Drupal\node\Controller\NodeController implements ContainerInjectionInterface
Expanded class hierarchy of WorkbenchContentController
File
- src/
Controller/ WorkbenchContentController.php, line 13
Namespace
Drupal\workbench\ControllerView source
class WorkbenchContentController extends NodeController {
/**
* Simple page to show list of content type to create.
*
* @see hook_workbench_create_alter()
*
* @return array
* A Render API array of content creation options.
*/
public function addPage() {
$output = parent::addPage();
// Allow other modules to add content here.
\Drupal::moduleHandler()
->alter('workbench_create', $output);
return $output;
}
/**
* Page callback for the workbench content page.
*
* Note that we add Views information to the array and render
* the Views as part of the alter hook provided here.
*
* @see hook_workbench_content_alter()
*
* @return array
* A Render API array of content creation options.
*/
public function content() {
$blocks = [];
$settings = $this
->getSettings();
// This left column is given a width of 35% by workbench.myworkbench.css.
$blocks['workbench_current_user'] = [
'#view_id' => $settings['overview_left']['view_id'],
'#view_display' => $settings['overview_left']['display_id'],
'#attributes' => [
'class' => [
'workbench-left',
],
],
];
// This right column is given a width of 65% by workbench.myworkbench.css.
$blocks['workbench_edited'] = [
'#view_id' => $settings['overview_right']['view_id'],
'#view_display' => $settings['overview_right']['display_id'],
'#attributes' => [
'class' => [
'workbench-right',
],
],
];
$blocks['workbench_recent_content'] = [
'#view_id' => $settings['overview_main']['view_id'],
'#view_display' => $settings['overview_main']['display_id'],
'#attributes' => [
'class' => [
'workbench-full',
'workbench-spacer',
],
],
];
// Allow other modules to alter the default page.
$context = 'overview';
\Drupal::moduleHandler()
->alter('workbench_content', $blocks, $context);
return $this
->renderBlocks($blocks);
}
/**
* Page callback for the workbench content page.
*
* Note that we add Views information to the array and render
* the Views as part of the alter hook provided here.
*
* @see hook_workbench_content_alter()
*
* @return array
* A Render API array of content creation options.
*/
public function editedContent() {
$blocks = [];
$settings = $this
->getSettings();
$blocks['workbench_edited_content'] = [
'#view_id' => $settings['edits_main']['view_id'],
'#view_display' => $settings['edits_main']['display_id'],
'#attributes' => [
'class' => [
'workbench-full',
],
],
];
// Allow other modules to alter the default page.
$context = 'edits';
\Drupal::moduleHandler()
->alter('workbench_content', $blocks, $context);
return $this
->renderBlocks($blocks);
}
/**
* Page callback for the workbench content page.
*
* Note that we add Views information to the array and render
* the Views as part of the alter hook provided here.
*
* @see hook_workbench_content_alter()
*
* @return array
* A Render API array of content creation options.
*/
public function allContent() {
$blocks = [];
$settings = $this
->getSettings();
$blocks['workbench_recent_content'] = [
'#view_id' => $settings['all_main']['view_id'],
'#view_display' => $settings['all_main']['display_id'],
'#attributes' => [
'class' => [
'workbench-full',
],
],
];
// Allow other modules to alter the default page.
$context = 'all';
\Drupal::moduleHandler()
->alter('workbench_content', $blocks, $context);
return $this
->renderBlocks($blocks);
}
/**
* Render the registered blocks as output.
*
* @param $blocks
* An array of block items formatted for rendering a view.
*
* @see hook_workbench_content_alter()
*/
public function renderBlocks($blocks) {
$output = [];
// Render each block element.
foreach ($blocks as $key => $block) {
if (empty($block['#view_id']) || !Views::getView($block['#view_id'])) {
$build = $block;
}
else {
$view_id = $block['#view_id'];
$display_id = $block['#view_display'];
// Create a view embed for this content.
$build = views_embed_view($view_id, $display_id);
}
if (!isset($build['#attributes'])) {
$build['#attributes'] = $block['#attributes'];
}
else {
$build['#attributes'] = array_merge_recursive($build['#attributes'], $block['#attributes']);
}
$output[] = $build;
}
return [
'blocks' => $output,
'#prefix' => '<div class="admin my-workbench">',
'#suffix' => '</div>',
'#attached' => [
'library' => [
'workbench/workbench.content',
],
],
];
}
/**
* Gets the content settings and prepares views information.
*/
public function getSettings() {
$config = $this
->config('workbench.settings');
$items = [
'overview_left' => $this
->t('Overview block left'),
'overview_right' => $this
->t('Overview block right'),
'overview_main' => $this
->t('Overview block main'),
'edits_main' => $this
->t('My edits main'),
'all_main' => $this
->t('All content main'),
];
foreach ($items as $key => $item) {
$setting = $config
->get($key);
$data = explode(':', $setting);
$settings[$key]['view_id'] = $data[0];
$settings[$key]['display_id'] = $data[1];
}
return $settings;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ControllerBase:: |
protected | property | The configuration factory. | |
ControllerBase:: |
protected | property | The current user service. | 1 |
ControllerBase:: |
protected | property | The entity form builder. | |
ControllerBase:: |
protected | property | The entity manager. | |
ControllerBase:: |
protected | property | The entity type manager. | |
ControllerBase:: |
protected | property | The form builder. | 2 |
ControllerBase:: |
protected | property | The key-value storage. | 1 |
ControllerBase:: |
protected | property | The language manager. | 1 |
ControllerBase:: |
protected | property | The module handler. | 2 |
ControllerBase:: |
protected | property | The state service. | |
ControllerBase:: |
protected | function | Returns the requested cache bin. | |
ControllerBase:: |
protected | function | Retrieves a configuration object. | |
ControllerBase:: |
private | function | Returns the service container. | |
ControllerBase:: |
protected | function | Returns the current user. | 1 |
ControllerBase:: |
protected | function | Retrieves the entity form builder. | |
ControllerBase:: |
protected | function | Retrieves the entity manager service. | |
ControllerBase:: |
protected | function | Retrieves the entity type manager. | |
ControllerBase:: |
protected | function | Returns the form builder service. | 2 |
ControllerBase:: |
protected | function | Returns a key/value storage collection. | 1 |
ControllerBase:: |
protected | function | Returns the language manager service. | 1 |
ControllerBase:: |
protected | function | Returns the module handler. | 2 |
ControllerBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
ControllerBase:: |
protected | function | Returns the state storage service. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
NodeController:: |
protected | property | The date formatter service. | |
NodeController:: |
protected | property | The entity repository service. | |
NodeController:: |
protected | property | The renderer service. | |
NodeController:: |
public | function | Provides the node submission form. | |
NodeController:: |
public | function | The _title_callback for the node.add route. | |
NodeController:: |
public static | function |
Instantiates a new instance of this class. Overrides ControllerBase:: |
|
NodeController:: |
protected | function | Gets a list of node revision IDs for a specific node. | |
NodeController:: |
public | function | Generates an overview table of older revisions of a node. | |
NodeController:: |
public | function | Page title callback for a node revision. | |
NodeController:: |
public | function | Displays a node revision. | |
NodeController:: |
public | function | Constructs a NodeController object. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. | |
WorkbenchContentController:: |
public | function |
Simple page to show list of content type to create. Overrides NodeController:: |
|
WorkbenchContentController:: |
public | function | Page callback for the workbench content page. | |
WorkbenchContentController:: |
public | function | Page callback for the workbench content page. | |
WorkbenchContentController:: |
public | function | Page callback for the workbench content page. | |
WorkbenchContentController:: |
public | function | Gets the content settings and prepares views information. | |
WorkbenchContentController:: |
public | function | Render the registered blocks as output. |