Drupal 8 で、自身のホスト名を取得する方法
\Drupal::request()->getHost()
を使う。これだけではhttps://〜から始まる URL ではないため、
$hostname = sprintf('https://%s/', \Drupal::request()->getHost());
などとする。
\Drupal::request()->getHost()
を使う。これだけではhttps://〜から始まる URL ではないため、
$hostname = sprintf('https://%s/', \Drupal::request()->getHost());
などとする。
$entity->toLink(..)という便利なヘルパー関数があるらしい。最後は->toString()で文字列にして$this->t(...)に渡す。
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,
];
}
以下の例では、['active']['data']のように、['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);
}
リスト中なので、チェックボックスは表示するだけて編集不可にしたいが、その場合は
以下は、現在の日時を出力する。
print \Drupal::service('date.formatter')->format((new \DateTime())->getTimeStamp(), 'short');
**秘密鍵(プライベートキー / Private Key)は、ダウンロードできない。**サーバ証明書しかダウンロードできない。
aws acm get-certificate --region us-east-1 --certificate-arn arn:aws:acm:us-east-1:123456789012:certificate/12345678-1234-1234-1234-123456789012
アウトプットは以下のように証明書と中間証明書が JSON フォーマットに入っている。
以下の static メソッド\Drupal::service('uuid')->generate()をコールする。
$uuid = \Drupal::service('uuid')->generate();
以下の 1行。$email には確認したい Email アドレスが入る。
\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();
Zend Framework v2 のインストールは
composer require zendframework/zendframework
でよいが、Zend Framework v1 はすでに Obsolete となっており、手動でインストールする場合は GitHub からライブラリをダウンロードして自身のアプリケーションパスにコピーする。
Drupal 8 で、カスタムブロックだけを提供するモジュールを作成するには、例としてmy_custom_block.info.ymlとMyCustomBlock.phpの 2つのファイルを書くだけでよいが、設定フィールドを翻訳可能にするには、3つ目のファイルであるスキーマファイルmy_custom_block.ymlを用意すればよい。