Drupal 8: How to Get the Site Hostname
\Drupal::request()->getHost()
This one doesn't include the URL that begins with https://〜, therefore you may want to write it as follows:
$hostname = sprintf('https://%s/', \Drupal::request()->getHost());
\Drupal::request()->getHost()
This one doesn't include the URL that begins with https://〜, therefore you may want to write it as follows:
$hostname = sprintf('https://%s/', \Drupal::request()->getHost());
Drupal 8 provides a useful helper funciton $entity->toLink(..). You must return it by converting to a string by using ->toString() at the end.
public function foo(Request $request = NULL) {
$id = $request->get('id'); // from query string
$entity = YourEntity::load($id);
$message = $this->t('Check at @url.', [
'@url' => $entity->toLink('<TEXT_TO_LINK_HERE>', 'edit-form')->toString(),
]);
return [
'#type' => 'markup',
'#markup' => $message,
];
}
For example shown below, ['data'] requires after ['active'] like ['active']['data'].
public function buildRow(EntityInterface $entity) {
$row['active']['data'] = [ // @IMPORTANT: add ['data'] here
'#type' => 'checkbox',
'#default_value' => (bool) $entity->isActive(),
'#checked' => (bool) $entity->isActive(),
'#attributes' => ['disabled' => 'disabled'],
'#disabled' => TRUE,
];
return $row + parent::buildRow($entity);
}
You can output the current date and time as follows:
print \Drupal::service('date.formatter')->format((new \DateTime())->getTimeStamp(), 'short');
You cannot download a private key. You can only download the Server certs.
aws acm get-certificate --region us-east-1 --certificate-arn arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012
Call the following static method\Drupal::service('uuid')->generate()
$uuid = \Drupal::service('uuid')->generate();
Put an Email address into $email that needs to be validated.
\Drupal::service('email.validator')->isValid($email);
$uid = \Drupal::currentUser()->id() // if you wan to get a username of the current user
$account = \Drupal\user\Entity\User::load($uid); // pass your uid
$username = $account->getUsername();
You can install Zend Framework v2 as follows:
composer require zendframework/zendframework
However Zend Framework v1 has already been obsolete, therefore when you want to install it manually, you need to download the library from GitHub, and copy (move) to your application directory.
Download Zend Framework v1 library from GitHub (Note that the following example is aimed for minimal package. If you want to install the full package, delete a -minimal portion. Also note that the following command line is just one line, even though it has new lines.)
If you want to create a module that provides your custom block(s) in Drupal 8, for instance, you can only write two source codes such as my_custom_block.info.yml and MyCustomBlock.php. However how can you make custom configuration fields on your custom block translatable? The answer is to add one additional file my_custom_block.yml as a schema file.