Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / modules / contrib / crop / src / Entity / CropType.php
1 <?php
2
3 namespace Drupal\crop\Entity;
4
5 use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
6 use Drupal\crop\CropTypeInterface;
7 use Symfony\Component\Validator\ConstraintViolationList;
8
9 /**
10  * Defines the Crop type configuration entity.
11  *
12  * @ConfigEntityType(
13  *   id = "crop_type",
14  *   label = @Translation("Crop type"),
15  *   handlers = {
16  *     "form" = {
17  *       "add" = "Drupal\crop\Form\CropTypeForm",
18  *       "edit" = "Drupal\crop\Form\CropTypeForm",
19  *       "delete" = "Drupal\crop\Form\CropTypeDeleteForm"
20  *     },
21  *     "list_builder" = "Drupal\crop\CropTypeListBuilder",
22  *   },
23  *   admin_permission = "administer crop types",
24  *   config_prefix = "type",
25  *   bundle_of = "crop",
26  *   entity_keys = {
27  *     "id" = "id",
28  *     "label" = "label",
29  *   },
30  *   links = {
31  *     "edit-form" = "/admin/config/media/crop/manage/{crop_type}",
32  *     "delete-form" = "/admin/config/media/crop/manage/{crop_type}/delete",
33  *   },
34  *   constraints = {
35  *     "CropTypeMachineNameValidation" = {},
36  *     "CropTypeAspectRatioValidation" = {},
37  *   }
38  * )
39  */
40 class CropType extends ConfigEntityBundleBase implements \IteratorAggregate, CropTypeInterface {
41
42   /**
43    * The machine name of this crop type.
44    *
45    * @var string
46    */
47   public $id;
48
49   /**
50    * The human-readable name of the crop type.
51    *
52    * @var string
53    */
54   public $label;
55
56   /**
57    * A brief description of this crop type.
58    *
59    * @var string
60    */
61   public $description;
62
63   /**
64    * The ratio of the image of this crop type.
65    *
66    * @var string
67    */
68   public $aspect_ratio;
69
70   /**
71    * Soft limit width in px.
72    *
73    * @var int
74    */
75   public $soft_limit_width;
76
77   /**
78    * Soft limit height in px.
79    *
80    * @var int
81    */
82   public $soft_limit_height;
83
84   /**
85    * Hard limit width in px.
86    *
87    * @var int
88    */
89   public $hard_limit_width;
90
91   /**
92    * Hard limit height in px.
93    *
94    * @var int
95    */
96   public $hard_limit_height;
97
98   /**
99    * {@inheritdoc}
100    */
101   public function id() {
102     return $this->id;
103   }
104
105   /**
106    * {@inheritdoc}
107    */
108   public function getAspectRatio() {
109     return $this->aspect_ratio;
110   }
111
112   /**
113    * {@inheritdoc}
114    */
115   public function validate() {
116     $violations = $this->getTypedData()->validate();
117     return new ConstraintViolationList(iterator_to_array($violations));
118   }
119
120   /**
121    * {@inheritdoc}
122    */
123   public function getIterator() {
124     return new \ArrayIterator();
125   }
126
127   /**
128    * {@inheritdoc}
129    */
130   public static function getCropTypeNames() {
131     return array_map(
132       function ($bundle_info) {
133         return $bundle_info['label'];
134       },
135       \Drupal::service('entity_type.bundle.info')->getBundleInfo('crop')
136     );
137   }
138
139   /**
140    * {@inheritdoc}
141    */
142   public function getSoftLimit() {
143     return [
144       'width' => $this->soft_limit_width,
145       'height' => $this->soft_limit_height,
146     ];
147   }
148
149   /**
150    * {@inheritdoc}
151    */
152   public function getHardLimit() {
153     return [
154       'width' => $this->hard_limit_width,
155       'height' => $this->hard_limit_height,
156     ];
157   }
158
159 }