CustomBlockType.php 2.51 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\EntityStorageControllerInterface;
12
use Drupal\custom_block\CustomBlockTypeInterface;
13 14 15 16

/**
 * Defines the custom block type entity.
 *
17
 * @ConfigEntityType(
18 19
 *   id = "custom_block_type",
 *   label = @Translation("Custom block type"),
20 21
 *   controllers = {
 *     "form" = {
22
 *       "default" = "Drupal\custom_block\CustomBlockTypeFormController",
23 24
 *       "add" = "Drupal\custom_block\CustomBlockTypeFormController",
 *       "edit" = "Drupal\custom_block\CustomBlockTypeFormController",
25
 *       "delete" = "Drupal\custom_block\Form\CustomBlockTypeDeleteForm"
26 27
 *     },
 *     "list" = "Drupal\custom_block\CustomBlockTypeListController"
28
 *   },
29
 *   admin_permission = "administer blocks",
30
 *   config_prefix = "type",
31
 *   bundle_of = "custom_block",
32 33 34 35
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "label",
 *     "uuid" = "uuid"
36 37
 *   },
 *   links = {
38
 *     "delete-form" = "custom_block.type_delete",
39
 *     "edit-form" = "custom_block.type_edit"
40 41 42
 *   }
 * )
 */
43
class CustomBlockType extends ConfigEntityBase implements CustomBlockTypeInterface {
44 45 46 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

  /**
   * 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;

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

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

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

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

108
}