Changed name of Profile entity to Hat
so as not to conflict with Profile or Profile2 module on existing sites
This commit is contained in:
44
src/Plugin/Block/HatCreator.php
Normal file
44
src/Plugin/Block/HatCreator.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Drupal\zencrm\Plugin\Block;
|
||||
|
||||
use Drupal\Core\Block\BlockBase;
|
||||
|
||||
/**
|
||||
* Provides a 'HatCreator' block.
|
||||
*
|
||||
* @Block(
|
||||
* id = "hat_creator",
|
||||
* admin_label = @Translation("Hat creator"),
|
||||
* )
|
||||
*/
|
||||
class HatCreator extends BlockBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function build() {
|
||||
$person_id = \Drupal::routeMatch()->getParameter('person')->id();
|
||||
$markup = "";
|
||||
|
||||
// Only offer hat creation on hats they don't already have.
|
||||
$hat_types = \Drupal::service('entity_type.bundle.info')->getBundleInfo('hat');
|
||||
foreach($hat_types as $id => $type) {
|
||||
$hats = \Drupal::entityTypeManager()
|
||||
->getStorage('hat')
|
||||
->loadByProperties(['type' => $id, 'person' => $person_id]);
|
||||
if (!reset($hats)) {
|
||||
$label = $type['label'];
|
||||
$markup .= "<p><a class='use-ajax' data-dialog-type='modal' href='/zencrm/hat/add/$id/$person_id'>Create $label Hat</a></p>";
|
||||
}
|
||||
}
|
||||
return [
|
||||
'#cache' => [
|
||||
'max-age' => 0,
|
||||
],
|
||||
'#markup' => "<div>$markup</div>"
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user