CarouselItem.php in bootstrap simple carousel 8
File
src/Entity/CarouselItem.php
View source
<?php
namespace Drupal\bootstrap_simple_carousel\Entity;
use Drupal\bootstrap_simple_carousel\CarouselItemInterface;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
class CarouselItem extends ContentEntityBase implements CarouselItemInterface {
private function getValue($field_name) {
if (!isset($this->values[$field_name][$this->activeLangcode])) {
$list = $this
->getTranslatedField($field_name, $this->activeLangcode)
->first();
return NULL !== $list ? $list
->getString() : NULL;
}
return $this->values[$field_name][$this->activeLangcode] ?? NULL;
}
private function setValue($field_name, $field_value) {
if (isset($this->values[$field_name])) {
$this->values[$field_name][$this->activeLangcode] = $field_value;
}
return $this;
}
public function getImageId() {
return $this
->getValue('image_id');
}
public function setImageId(int $imageId) {
return $this
->setValue('image_id', $imageId);
}
public function getImageAlt() {
return $this
->getValue('image_alt');
}
public function setImageAlt(string $imageAlt) {
return $this
->setValue('image_alt', $imageAlt);
}
public function getImageTitle() {
return $this
->getValue('image_title');
}
public function setImageTitle(string $imageTitle) {
return $this
->setValue('image_title', $imageTitle);
}
public function getImageLink() {
return $this
->getValue('image_link');
}
public function setImageLink(string $imageLink) {
return $this
->setValue('image_link', $imageLink);
}
public function getCaptionTitle() {
return $this
->getValue('caption_title');
}
public function setCaptionTitle(string $captionTitle) {
return $this
->setValue('caption_title', $captionTitle);
}
public function getCaptionText() {
return $this
->getValue('caption_text');
}
public function setCaptionText(string $captionText) {
return $this
->setValue('caption_text', $captionText);
}
public function getWeight() {
return $this
->getValue('weight');
}
public function setWeight(int $weight) {
return $this
->setValue('weight', $weight);
}
public function getStatus() {
return $this
->getValue('status');
}
public function setStatus(int $status) {
return $this
->setValue('status', $status);
}
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['image_id'] = BaseFieldDefinition::create('integer')
->setLabel(t('Image id'))
->setDescription(t('The id of image file.'))
->setSetting('unsigned', TRUE);
$fields['image_alt'] = BaseFieldDefinition::create('string')
->setLabel(t('Image Alt'))
->setDescription(t('The alt of image.'))
->setSetting('max_length', 255);
$fields['image_title'] = BaseFieldDefinition::create('string')
->setLabel(t('Image Title'))
->setDescription(t('The title of image.'))
->setSetting('max_length', 255);
$fields['image_link'] = BaseFieldDefinition::create('string')
->setLabel(t('Image Link'))
->setDescription(t('The link of image.'))
->setSetting('max_length', 255);
$fields['caption_title'] = BaseFieldDefinition::create('string')
->setLabel(t('Caption Title'))
->setDescription(t('The title of caption.'))
->setSetting('max_length', 100);
$fields['caption_text'] = BaseFieldDefinition::create('string')
->setLabel(t('Caption Text'))
->setDescription(t('The text of caption.'))
->setSetting('max_length', 255);
$fields['weight'] = BaseFieldDefinition::create('integer')
->setLabel(t('Weight'))
->setDescription(t('The weight of the item.'))
->setSetting('unsigned', TRUE);
$fields['status'] = BaseFieldDefinition::create('integer')
->setLabel(t('Status'))
->setDescription(t('The status of item.'))
->setSetting('unsigned', TRUE);
return $fields;
}
}