Bash: How to replace a string in a directory recursively
Combine find, xargs and sed.
find . -name "*.css" | xargs sed -i 's/BEFORE/AFTER/g'
Combine find, xargs and sed.
find . -name "*.css" | xargs sed -i 's/BEFORE/AFTER/g'
Define a function echo_count and count the function name to be called in the script. You can refer to a variable ${TOTAL} .For example,
#!/bin/bash
export TOTAL=$(( $(grep '^echo_count' $0 | wc -l) ))
export COUNT=1
function echo_count () {
echo -n "($(( COUNT++ ))/${TOTAL}) $1"
}
echo
echo_count 'Processing one - Stopping Apache2... '
sudo service apache2 stop
echo 'Done'
echo_count 'Processing two - '
echo 'Apache2 is not working.'
#!/bin/bash
export TARGET_DIR='./' # Current directory
export ORIGINAL_NAME='xxxxx'
export TARGET_NAME='yyyyy'
find "${TARGET_DIR}" -name '*${ORIGINAL_NAME}*' -execdir rename "s/${ORIGINAL_NAME}/${TARGET_NAME}/g" '{}' \;
\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());
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);
}
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,
];
}
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);