View source
<?php
namespace Drupal\registration;
use Drupal\Core\Entity\Annotation\ContentEntityType;
use Drupal\Core\Entity\Entity;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
class Registration extends EntityContentBase implements RegistrationInterface {
public $registration_id, $type, $entity_id, $entity_type, $anon_mail = NULL, $user_uid = NULL, $count, $author_uid, $state, $created, $updated;
protected function label() {
$wrapper = entity_metadata_wrapper('registration', $this);
$host = $wrapper->entity
->value();
if ($host) {
return t('Registration for !title', array(
'!title' => $host
->label(),
));
}
return '';
}
public function buildContent($view_mode = 'full', $langcode = NULL) {
$build = parent::buildContent($view_mode, $langcode);
$wrapper = entity_metadata_wrapper('registration', $this);
$host_entity_type_info = \Drupal::entityManager()
->getDefinition($this->entity_type);
$host_entity = $wrapper->entity
->value();
$state = $wrapper->state
->value();
$author = $wrapper->author
->value();
$user = $wrapper->user
->value();
list(, , $host_entity_bundle) = entity_extract_ids($this->entity_type, $host_entity);
$host_label = $host_entity
->label();
$host_uri = $host_entity ? entity_uri($this->entity_type, $host_entity) : NULL;
$build['mail'] = array(
'#theme' => 'registration_property_field',
'#label' => t('Email Address'),
'#items' => array(
array(
'#markup' => $wrapper->mail
->value(),
),
),
'#classes' => 'field field-label-inline clearfix',
);
$host_entity_link_label = isset($host_entity_type_info['bundles'][$host_entity_bundle]['label']) ? '<div class="field-label">' . $host_entity_type_info['bundles'][$host_entity_bundle]['label'] . '</div>' : '';
$build['created'] = array(
'#theme' => 'registration_property_field',
'#label' => t('Created'),
'#items' => array(
array(
'#markup' => format_date($this->created),
),
),
'#classes' => 'field field-label-inline clearfix',
);
$build['updated'] = array(
'#theme' => 'registration_property_field',
'#label' => t('Updated'),
'#items' => array(
array(
'#markup' => format_date($this->updated),
),
),
'#classes' => 'field field-label-inline clearfix',
);
$build['slots'] = array(
'#theme' => 'registration_property_field',
'#label' => t('Slots Used'),
'#items' => array(
array(
'#markup' => $this->count,
),
),
'#classes' => 'field field-label-inline clearfix',
);
if ($author) {
$build['author'] = array(
'#theme' => 'registration_property_field',
'#label' => t('Author'),
'#items' => array(
array(
'#markup' => _theme('username', array(
'account' => $author,
)),
),
),
'#classes' => 'field field-label-inline clearfix',
'#attributes' => '',
);
}
if ($user) {
$build['user'] = array(
'#theme' => 'registration_property_field',
'#label' => t('User'),
'#items' => array(
array(
'#markup' => _theme('username', array(
'account' => $user,
)),
),
),
'#classes' => 'field field-label-inline clearfix',
'#attributes' => '',
);
}
$build['state'] = array(
'#theme' => 'registration_property_field',
'#label' => t('State'),
'#items' => array(
array(
'#markup' => $state ? filter_xss_admin($state
->label()) : '',
),
),
'#classes' => 'field field-label-inline clearfix',
);
return $build;
}
public function save() {
$wrapper = entity_metadata_wrapper('registration', $this);
$state = $wrapper->state
->value();
if (!$state) {
$default_state = registration_get_default_state($wrapper->type
->value());
if ($default_state) {
$this->state = $default_state
->identifier();
}
}
$this->updated = REQUEST_TIME;
if (!$this->registration_id && empty($this->created)) {
$this->created = REQUEST_TIME;
}
return parent::save();
}
protected function defaultUri() {
return array(
'path' => 'registration/' . $this
->internalIdentifier(),
);
}
public function registrant_type($account) {
$reg_type = NULL;
if (!empty($account)) {
if ($account->uid && $account->uid === $this->user_uid) {
$reg_type = REGISTRATION_REGISTRANT_TYPE_ME;
}
elseif ($this->user_uid) {
$reg_type = REGISTRATION_REGISTRANT_TYPE_USER;
}
}
if (!empty($this->anon_mail)) {
$reg_type = REGISTRATION_REGISTRANT_TYPE_ANON;
}
return $reg_type;
}
}