CourseType.php in Course 3.x
Same filename in this branch
Same filename and directory in other branches
Namespace
Drupal\course\EntityFile
src/Entity/CourseType.phpView source
<?php
namespace Drupal\course\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
use Drupal\Core\Entity\RevisionableEntityBundleInterface;
/**
* Defines the course type entity class.
*
* @ConfigEntityType(
* id = "course_type",
* label = @Translation("Course type"),
* label_collection = @Translation("Course types"),
* label_singular = @Translation("course type"),
* label_plural = @Translation("course types"),
* label_count = @PluralTranslation(
* singular = "@count course type",
* plural = "@count course types",
* ),
* admin_permission = "administer course",
* config_prefix = "type",
* bundle_of = "course",
* entity_keys = {
* "id" = "id",
* "label" = "label"
* },
* config_export = {
* "id",
* "label",
* "new_revision",
* "outline",
* "status",
* },
* handlers = {
* "route_provider" = {
* "html" = "Drupal\Core\Entity\Routing\AdminHtmlRouteProvider",
* },
* "list_builder" = "Drupal\course\Config\Entity\CourseTypeListBuilder",
* "form" = {
* "default" = "Drupal\Core\Entity\ContentEntityForm",
* "add" = "Drupal\course\Form\CourseTypeForm",
* "edit" = "Drupal\course\Form\CourseTypeForm",
* "delete" = "Drupal\Core\Entity\EntityDeleteForm",
* },
* },
* links = {
* "add-form" = "/admin/course/course-types/add",
* "edit-form" = "/admin/course/course-types/manage/{course_type}",
* "delete-form" = "/admin/course/course-types/manage/{course_type}/delete",
* "collection" = "/admin/course/course-types"
* }
* )
*/
class CourseType extends ConfigEntityBundleBase implements RevisionableEntityBundleInterface {
/**
* Should courses of this type always generate revisions.
*
* @var bool
*/
protected $new_revision = FALSE;
public function shouldCreateNewRevision() {
return $this->new_revision;
}
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
$status = (bool) $this
->get('status');
$outline = $this
->get('outline');
$fields = \Drupal::service('entity_field.manager')
->getFieldDefinitions('course', $this
->id());
$fields['status']
->getConfig($this
->id())
->setDefaultValue($status)
->save();
$fields['outline']
->getConfig($this
->id())
->setDefaultValue($outline)
->save();
\Drupal::service('entity_field.manager')
->clearCachedFieldDefinitions();
}
}
Classes
Name | Description |
---|---|
CourseType | Defines the course type entity class. |