3 namespace Drupal\crop\Entity;
5 use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
6 use Drupal\crop\CropTypeInterface;
7 use Symfony\Component\Validator\ConstraintViolationList;
10 * Defines the Crop type configuration entity.
14 * label = @Translation("Crop type"),
17 * "add" = "Drupal\crop\Form\CropTypeForm",
18 * "edit" = "Drupal\crop\Form\CropTypeForm",
19 * "delete" = "Drupal\crop\Form\CropTypeDeleteForm"
21 * "list_builder" = "Drupal\crop\CropTypeListBuilder",
23 * admin_permission = "administer crop types",
24 * config_prefix = "type",
31 * "edit-form" = "/admin/config/media/crop/manage/{crop_type}",
32 * "delete-form" = "/admin/config/media/crop/manage/{crop_type}/delete",
35 * "CropTypeMachineNameValidation" = {},
36 * "CropTypeAspectRatioValidation" = {},
40 class CropType extends ConfigEntityBundleBase implements \IteratorAggregate, CropTypeInterface {
43 * The machine name of this crop type.
50 * The human-readable name of the crop type.
57 * A brief description of this crop type.
64 * The ratio of the image of this crop type.
71 * Soft limit width in px.
75 public $soft_limit_width;
78 * Soft limit height in px.
82 public $soft_limit_height;
85 * Hard limit width in px.
89 public $hard_limit_width;
92 * Hard limit height in px.
96 public $hard_limit_height;
101 public function id() {
108 public function getAspectRatio() {
109 return $this->aspect_ratio;
115 public function validate() {
116 $violations = $this->getTypedData()->validate();
117 return new ConstraintViolationList(iterator_to_array($violations));
123 public function getIterator() {
124 return new \ArrayIterator();
130 public static function getCropTypeNames() {
132 function ($bundle_info) {
133 return $bundle_info['label'];
135 \Drupal::service('entity_type.bundle.info')->getBundleInfo('crop')
142 public function getSoftLimit() {
144 'width' => $this->soft_limit_width,
145 'height' => $this->soft_limit_height,
152 public function getHardLimit() {
154 'width' => $this->hard_limit_width,
155 'height' => $this->hard_limit_height,