Skip to content
Snippets Groups Projects
Commit acd420e9 authored by simon's avatar simon
Browse files

add: shareconversion entity

No related merge requests found
Pipeline #650 passed with warnings with stages
in 8 minutes and 21 seconds
Showing
with 732 additions and 1 deletion
<?php
/**
* @file
* Contains share_conversion.page.inc.
*
* Page callback for Share conversion entities.
*/
use Drupal\Core\Render\Element;
/**
* Prepares variables for Share conversion templates.
*
* Default template: share_conversion.html.twig.
*
* @param array $variables
* An associative array containing:
* - elements: An associative array containing the user information and any
* - attributes: HTML attributes for the containing element.
*/
function template_preprocess_share_conversion(array &$variables) {
// Fetch ShareConversion Entity Object.
$share_conversion = $variables['elements']['#share_conversion'];
// Helpful $content variable for templates.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
......@@ -64,3 +64,8 @@ entity.share_issue.add_form:
title: 'Add Share issue'
appears_on:
- entity.share_issue.collection
entity.share_conversion.add_form:
route_name: entity.share_conversion.add_form
title: 'Add Share conversion'
appears_on:
- entity.share_conversion.collection
......@@ -116,3 +116,18 @@ shareholder_register.export_shareholder_register:
description: 'Export the state of the shareholder register at date.'
route_name: shareholder_register.export_shareholder_register_form
parent: system.admin.shareholder_register.tools
# Share conversion menu items definition
entity.share_conversion.collection:
title: 'Share conversions'
route_name: entity.share_conversion.collection
description: 'Share conversions'
parent: entity.shareholder_register
weight: 100
share_conversion.admin.structure.settings:
title: 'Share conversion settings'
description: 'Configure Share conversion entities'
route_name: share_conversion.settings
parent: entity.shareholder_register.config
weigth: 1000
......@@ -180,3 +180,24 @@ entity.share_issue.collection:
base_route: entity.share_type.collection
title: 'Share Issues'
weight: 500
# Share conversion routing definition
share_conversion.settings_tab:
route_name: share_conversion.settings
title: 'Settings'
base_route: share_conversion.settings
entity.share_conversion.canonical:
route_name: entity.share_conversion.canonical
base_route: entity.share_conversion.canonical
title: 'View'
entity.share_conversion.edit_form:
route_name: entity.share_conversion.edit_form
base_route: entity.share_conversion.canonical
title: 'Edit'
entity.share_conversion.delete_form:
route_name: entity.share_conversion.delete_form
base_route: entity.share_conversion.canonical
title: Delete
weight: 10
......@@ -113,3 +113,23 @@ edit share issue entities:
view all share issue entities:
title: 'View all Share issue entities'
add share conversion entities:
title: 'Create new Share conversion entities'
administer share conversion entities:
title: 'Administer Share conversion entities'
description: 'Allow to access the administration form to configure Share conversion entities.'
restrict access: true
delete share conversion entities:
title: 'Delete Share conversion entities'
edit share conversion entities:
title: 'Edit Share conversion entities'
view published share conversion entities:
title: 'View published Share conversion entities'
view unpublished share conversion entities:
title: 'View unpublished Share conversion entities'
......@@ -118,3 +118,4 @@ shareholder_register.export_shareholder_register_form:
_title: 'Export Shareholder Register'
requirements:
_permission: 'view all shareholder entities'
<?php
namespace Drupal\shareholder_register\Entity;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityChangedTrait;
use Drupal\Core\Entity\EntityPublishedTrait;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\user\UserInterface;
/**
* Defines the Share conversion entity.
*
* @ingroup shareholder_register
*
* @ContentEntityType(
* id = "share_conversion",
* label = @Translation("Share conversion"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\shareholder_register\ShareConversionListBuilder",
* "views_data" = "Drupal\shareholder_register\Entity\ShareConversionViewsData",
*
* "form" = {
* "default" = "Drupal\shareholder_register\Form\ShareConversionForm",
* "add" = "Drupal\shareholder_register\Form\ShareConversionForm",
* "edit" = "Drupal\shareholder_register\Form\ShareConversionForm",
* "delete" = "Drupal\shareholder_register\Form\ShareConversionDeleteForm",
* },
* "route_provider" = {
* "html" = "Drupal\shareholder_register\ShareConversionHtmlRouteProvider",
* },
* "access" = "Drupal\shareholder_register\ShareConversionAccessControlHandler",
* },
* base_table = "share_conversion",
* translatable = FALSE,
* admin_permission = "administer share conversion entities",
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid",
* "uid" = "user_id",
* "langcode" = "langcode",
* "published" = "status",
* },
* links = {
* "canonical" = "/admin/shareholder_register/share_conversion/{share_conversion}",
* "add-form" = "/admin/shareholder_register/share_conversion/add",
* "edit-form" = "/admin/shareholder_register/share_conversion/{share_conversion}/edit",
* "delete-form" = "/admin/shareholder_register/share_conversion/{share_conversion}/delete",
* "collection" = "/admin/shareholder_register/share_conversion",
* },
* field_ui_base_route = "share_conversion.settings"
* )
*/
class ShareConversion extends ContentEntityBase implements ShareConversionInterface {
use EntityChangedTrait;
use EntityPublishedTrait;
/**
* {@inheritdoc}
*/
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
$values += [
'user_id' => \Drupal::currentUser()->id(),
];
}
/**
* {@inheritdoc}
*/
public function getName() {
return $this->get('name')->value;
}
/**
* {@inheritdoc}
*/
public function setName($name) {
$this->set('name', $name);
return $this;
}
/**
* {@inheritdoc}
*/
public function getCreatedTime() {
return $this->get('created')->value;
}
/**
* {@inheritdoc}
*/
public function setCreatedTime($timestamp) {
$this->set('created', $timestamp);
return $this;
}
/**
* {@inheritdoc}
*/
public function getOwner() {
return $this->get('user_id')->entity;
}
/**
* {@inheritdoc}
*/
public function getOwnerId() {
return $this->get('user_id')->target_id;
}
/**
* {@inheritdoc}
*/
public function setOwnerId($uid) {
$this->set('user_id', $uid);
return $this;
}
/**
* {@inheritdoc}
*/
public function setOwner(UserInterface $account) {
$this->set('user_id', $account->id());
return $this;
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
// Add the published field.
$fields += static::publishedBaseFieldDefinitions($entity_type);
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Authored by'))
->setDescription(t('The user ID of author of the Share conversion entity.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'author',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the Share conversion entity.'))
->setSettings([
'max_length' => 50,
'text_processing' => 0,
])
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => -4,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => -4,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE);
$fields['date'] = BaseFieldDefinition::create('datetime')
->setLabel(t('Conversion Date'))
->setDescription(t('The Date of the Share conversion.'))
->setSettings(array(
'datetime_type' => 'date',
))
->setDefaultValue('')
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'string',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'string_textfield',
'weight' => 0,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['share_ids'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Shares'))
->setDescription(t('The Shares.'))
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
->setRevisionable(FALSE)
->setSettings(array(
'target_type' => 'share_transaction',
'default_value' => 0,
))
->setDisplayOptions('view', [
'label' => 'above',
'type' => 'share_transactions_formatter',
'weight' => 3,
])
->setDisplayOptions('form', [
'type' => 'entity_reference_autocomplete',
'weight' => 3,
'settings' => [
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
],
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['status']->setDescription(t('A boolean indicating whether the Share conversion is published.'))
->setDisplayOptions('form', [
'type' => 'boolean_checkbox',
'weight' => -3,
]);
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the entity was last edited.'));
return $fields;
}
}
<?php
namespace Drupal\shareholder_register\Entity;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityChangedInterface;
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\user\EntityOwnerInterface;
/**
* Provides an interface for defining Share conversion entities.
*
* @ingroup shareholder_register
*/
interface ShareConversionInterface extends ContentEntityInterface, EntityChangedInterface, EntityPublishedInterface, EntityOwnerInterface {
/**
* Add get/set methods for your configuration properties here.
*/
/**
* Gets the Share conversion name.
*
* @return string
* Name of the Share conversion.
*/
public function getName();
/**
* Sets the Share conversion name.
*
* @param string $name
* The Share conversion name.
*
* @return \Drupal\shareholder_register\Entity\ShareConversionInterface
* The called Share conversion entity.
*/
public function setName($name);
/**
* Gets the Share conversion creation timestamp.
*
* @return int
* Creation timestamp of the Share conversion.
*/
public function getCreatedTime();
/**
* Sets the Share conversion creation timestamp.
*
* @param int $timestamp
* The Share conversion creation timestamp.
*
* @return \Drupal\shareholder_register\Entity\ShareConversionInterface
* The called Share conversion entity.
*/
public function setCreatedTime($timestamp);
}
<?php
namespace Drupal\shareholder_register\Entity;
use Drupal\views\EntityViewsData;
/**
* Provides Views data for Share conversion entities.
*/
class ShareConversionViewsData extends EntityViewsData {
/**
* {@inheritdoc}
*/
public function getViewsData() {
$data = parent::getViewsData();
// Additional information for Views integration, such as table joins, can be
// put here.
return $data;
}
}
......@@ -541,7 +541,7 @@ class ShareTransaction extends ContentEntityBase implements ShareTransactionInte
$fields['date'] = BaseFieldDefinition::create('datetime')
->setLabel(t('Transaction Date'))
->setDescription(t('The Date of the Share transaction entity.'))
->setDescription(t('The Date of the Share transaction.'))
->setSettings(array(
'datetime_type' => 'date',
'wkf-editable' => ['state' => ['draft']],
......
<?php
namespace Drupal\shareholder_register\Form;
use Drupal\Core\Entity\ContentEntityDeleteForm;
/**
* Provides a form for deleting Share conversion entities.
*
* @ingroup shareholder_register
*/
class ShareConversionDeleteForm extends ContentEntityDeleteForm {
}
<?php
namespace Drupal\shareholder_register\Form;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Form controller for Share conversion edit forms.
*
* @ingroup shareholder_register
*/
class ShareConversionForm extends ContentEntityForm {
/**
* The current user account.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $account;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
// Instantiates this form class.
$instance = parent::create($container);
$instance->account = $container->get('current_user');
return $instance;
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
/* @var \Drupal\shareholder_register\Entity\ShareConversion $entity */
$form = parent::buildForm($form, $form_state);
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$entity = $this->entity;
$status = parent::save($form, $form_state);
switch ($status) {
case SAVED_NEW:
$this->messenger()->addMessage($this->t('Created the %label Share conversion.', [
'%label' => $entity->label(),
]));
break;
default:
$this->messenger()->addMessage($this->t('Saved the %label Share conversion.', [
'%label' => $entity->label(),
]));
}
$form_state->setRedirect('entity.share_conversion.canonical', ['share_conversion' => $entity->id()]);
}
}
<?php
namespace Drupal\shareholder_register\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class ShareConversionSettingsForm.
*
* @ingroup shareholder_register
*/
class ShareConversionSettingsForm extends FormBase {
/**
* Returns a unique string identifying the form.
*
* @return string
* The unique string identifying the form.
*/
public function getFormId() {
return 'shareconversion_settings';
}
/**
* Form submission handler.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Empty implementation of the abstract submit class.
}
/**
* Defines the settings form for Share conversion entities.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The current state of the form.
*
* @return array
* Form definition array.
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['shareconversion_settings']['#markup'] = 'Settings form for Share conversion entities. Manage field settings here.';
return $form;
}
}
<?php
namespace Drupal\shareholder_register;
use Drupal\Core\Entity\EntityAccessControlHandler;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Access\AccessResult;
/**
* Access controller for the Share conversion entity.
*
* @see \Drupal\shareholder_register\Entity\ShareConversion.
*/
class ShareConversionAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
/** @var \Drupal\shareholder_register\Entity\ShareConversionInterface $entity */
switch ($operation) {
case 'view':
if (!$entity->isPublished()) {
return AccessResult::allowedIfHasPermission($account, 'view unpublished share conversion entities');
}
return AccessResult::allowedIfHasPermission($account, 'view published share conversion entities');
case 'update':
return AccessResult::allowedIfHasPermission($account, 'edit share conversion entities');
case 'delete':
return AccessResult::allowedIfHasPermission($account, 'delete share conversion entities');
}
// Unknown operation, no opinion.
return AccessResult::neutral();
}
/**
* {@inheritdoc}
*/
protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
return AccessResult::allowedIfHasPermission($account, 'add share conversion entities');
}
}
<?php
namespace Drupal\shareholder_register;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
/**
* Provides routes for Share conversion entities.
*
* @see \Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
* @see \Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
*/
class ShareConversionHtmlRouteProvider extends AdminHtmlRouteProvider {
/**
* {@inheritdoc}
*/
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
$entity_type_id = $entity_type->id();
if ($settings_form_route = $this->getSettingsFormRoute($entity_type)) {
$collection->add("$entity_type_id.settings", $settings_form_route);
}
return $collection;
}
/**
* Gets the settings form route.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
* The entity type.
*
* @return \Symfony\Component\Routing\Route|null
* The generated route, if available.
*/
protected function getSettingsFormRoute(EntityTypeInterface $entity_type) {
if (!$entity_type->getBundleEntityType()) {
$route = new Route("/admin/structure/{$entity_type->id()}/settings");
$route
->setDefaults([
'_form' => 'Drupal\shareholder_register\Form\ShareConversionSettingsForm',
'_title' => "{$entity_type->getLabel()} settings",
])
->setRequirement('_permission', $entity_type->getAdminPermission())
->setOption('_admin_route', TRUE);
return $route;
}
}
}
<?php
namespace Drupal\shareholder_register;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityListBuilder;
use Drupal\Core\Link;
/**
* Defines a class to build a listing of Share conversion entities.
*
* @ingroup shareholder_register
*/
class ShareConversionListBuilder extends EntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['id'] = $this->t('Share conversion ID');
$header['name'] = $this->t('Name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/* @var \Drupal\shareholder_register\Entity\ShareConversion $entity */
$row['id'] = $entity->id();
$row['name'] = Link::createFromRoute(
$entity->label(),
'entity.share_conversion.edit_form',
['share_conversion' => $entity->id()]
);
return $row + parent::buildRow($entity);
}
}
{#
/**
* @file share_conversion.html.twig
* Default theme implementation to present Share conversion data.
*
* This template is used when viewing Share conversion pages.
*
*
* Available variables:
* - content: A list of content items. Use 'content' to print all content, or
* - attributes: HTML attributes for the container element.
*
* @see template_preprocess_share_conversion()
*
* @ingroup themeable
*/
#}
<div{{ attributes.addClass('share_conversion') }}>
{% if content %}
{{- content -}}
{% endif %}
</div>
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment