setCacheMaxAge(0); return $result; } /** * {@inheritdoc} */ public function tips($long = FALSE) { if ($long) { $output = '
' . t('Custom PHP code may be embedded in some types of site content, including posts and blocks. While embedding PHP code inside a post or block is a powerful and flexible feature when used by a trusted user with PHP experience, it is a significant and dangerous security risk when used improperly. Even a small mistake when posting PHP code may accidentally compromise your site.') . '
'; $output .= '' . t('If you are unfamiliar with PHP, SQL, or Drupal, avoid using custom PHP code within posts. Experimenting with PHP may corrupt your database, render your site inoperable, or significantly compromise security.') . '
'; $output .= '' . t('Notes:') . '
'; $output .= 'register_globals
is turned off. If you need to use forms, understand and use the functions in the Drupal Form API.', [':formapi' => 'https://api.drupal.org/api/group/form_api/8']) . 'print
or return
statement in your code to output content.') . '' . t('A basic example: Creating a "Welcome" block that greets visitors with a simple message.') . '
'; $output .= 'Add a custom block to your site, named "Welcome". With its text format set to "PHP code" (or another format supporting PHP input), add the following in the Block body:
print t(\'Welcome visitor! Thank you for visiting.\');') . '
To display the name of a registered user, use this instead:
$account = \Drupal::currentUser(); if ($account->isAuthenticated()) { print t(\'Welcome @name! Thank you for visiting.\', [\'@name\' => $account->getDisplayName()]); } else { print t(\'Welcome visitor! Thank you for visiting.\'); }') . '
' . t('Drupal.org offers some example PHP snippets, or you can create your own with some PHP experience and knowledge of the Drupal system.', [':drupal' => 'https://drupal.org', ':php-snippets' => 'https://drupal.org/documentation/customization/php-snippets']) . '
'; return $output; } else { return t('You may post PHP code. You should include <?php ?> tags.'); } } }