CustomBlockType.php 2.67 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\custom_block\Entity\CustomBlockType.
6 7
 */

8
namespace Drupal\custom_block\Entity;
9 10

use Drupal\Core\Config\Entity\ConfigEntityBase;
11
use Drupal\Core\Entity\Annotation\EntityType;
12
use Drupal\Core\Annotation\Translation;
13
use Drupal\Core\Entity\EntityStorageControllerInterface;
14
use Drupal\custom_block\CustomBlockTypeInterface;
15 16 17 18

/**
 * Defines the custom block type entity.
 *
19
 * @EntityType(
20 21 22
 *   id = "custom_block_type",
 *   label = @Translation("Custom block type"),
 *   module = "custom_block",
23
 *   controllers = {
24
 *     "storage" = "Drupal\Core\Config\Entity\ConfigStorageController",
25
 *     "access" = "Drupal\custom_block\CustomBlockTypeAccessController",
26
 *     "form" = {
27
 *       "default" = "Drupal\custom_block\CustomBlockTypeFormController",
28 29
 *       "add" = "Drupal\custom_block\CustomBlockTypeFormController",
 *       "edit" = "Drupal\custom_block\CustomBlockTypeFormController",
30
 *       "delete" = "Drupal\custom_block\Form\CustomBlockTypeDeleteForm"
31 32
 *     },
 *     "list" = "Drupal\custom_block\CustomBlockTypeListController"
33 34
 *   },
 *   config_prefix = "custom_block.type",
35
 *   bundle_of = "custom_block",
36 37 38 39
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "label",
 *     "uuid" = "uuid"
40 41 42
 *   },
 *   links = {
 *     "edit-form" = "admin/structure/block/custom-blocks/manage/{custom_block_type}"
43 44 45
 *   }
 * )
 */
46
class CustomBlockType extends ConfigEntityBase implements CustomBlockTypeInterface {
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

  /**
   * The custom block type ID.
   *
   * @var string
   */
  public $id;

  /**
   * The custom block type UUID.
   *
   * @var string
   */
  public $uuid;

  /**
   * The custom block type label.
   *
   * @var string
   */
  public $label;

  /**
   * The default revision setting for custom blocks of this type.
   *
   * @var bool
   */
  public $revision;

  /**
   * The description of the block type.
   *
   * @var string
   */
  public $description;

83 84 85 86
  /**
   * {@inheritdoc}
   */
  public function postSave(EntityStorageControllerInterface $storage_controller, $update = TRUE) {
87 88
    parent::postSave($storage_controller, $update);

89 90 91 92 93 94 95 96 97 98 99 100 101
    if (!$update) {
      entity_invoke_bundle_hook('create', 'custom_block', $this->id());
      custom_block_add_body_field($this->id);
    }
    elseif ($this->originalID != $this->id) {
      entity_invoke_bundle_hook('rename', 'custom_block', $this->originalID, $this->id);
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function postDelete(EntityStorageControllerInterface $storage_controller, array $entities) {
102 103
    parent::postDelete($storage_controller, $entities);

104 105 106 107
    foreach ($entities as $entity) {
      entity_invoke_bundle_hook('delete', 'custom_block', $entity->id());
    }
  }
108

109
}