Bash: Numbering the processing command

Submitted by admin on Thu, 04/18/2019 - 17:29

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.'

Tags

Drupal 8: How to Display Checkbox in List View

Submitted by admin on Sun, 03/04/2018 - 01:20

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);
}

Tags

Drupal 8: How to Return a Markup incl. a URL link

Submitted by admin on Sun, 03/04/2018 - 01:17

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,
];
}

Tags