Skip to content

Instantly share code, notes, and snippets.

@levmyshkin
Last active November 19, 2021 13:35
Show Gist options
  • Save levmyshkin/a4abe17a99909a3e1d2aca63df08ae85 to your computer and use it in GitHub Desktop.
Save levmyshkin/a4abe17a99909a3e1d2aca63df08ae85 to your computer and use it in GitHub Desktop.
Drupal: Creating pages for a premium account programmatically
name: DrupalBook
description: Custom module for learning Drupal
type: module
core: 8.x
core_version_requirement: ^8 || ^9
package: DrupalBook
access premium pages:
title: 'Access Premium pages'
description: 'A custom permission for your pages.'
restrict access: TRUE
drupalbook.private_content:
path: '/private-page'
defaults:
_controller: '\Drupal\drupalbook\Controller\FirstPageController::privateContent'
_title: 'Private content'
requirements:
_permission: 'access premium pages'
<?php
/**
* @file /modules/custom/drupalbook/src/Controller/FirstPageController.php
*/
namespace Drupal\drupalbook\Controller;
/**
* Provides route responses for the DrupalBook module.
*/
class FirstPageController {
/**
* Returns a private page.
*
* @return array
* A simple renderable array.
*/
public function privateContent() {
$element = array(
'#markup' => 'Private content',
);
return $element;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment