Saved reports (templates) are now just called "reports".

This commit is contained in:
Naomi
2018-09-17 08:48:20 +01:00
parent c81ebc4d94
commit d5fe23418e
13 changed files with 274 additions and 129 deletions

View File

@ -0,0 +1,57 @@
<?php
namespace Drupal\opencase_reporting\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
/**
* Defines the OpenCase Report entity.
*
* @ConfigEntityType(
* id = "opencase_report",
* label = @Translation("OpenCase Report"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\opencase_reporting\OpenCaseReportListBuilder",
* "form" = {
* "add" = "Drupal\opencase_reporting\Form\OpenCaseReportForm",
* "edit" = "Drupal\opencase_reporting\Form\OpenCaseReportForm",
* "delete" = "Drupal\opencase_reporting\Form\OpenCaseReportDeleteForm"
* },
* "route_provider" = {
* "html" = "Drupal\opencase_reporting\OpenCaseReportHtmlRouteProvider",
* },
* },
* config_prefix = "opencase_report",
* admin_permission = "administer site configuration",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "uuid" = "uuid"
* },
* links = {
* "canonical" = "/opencase/reporting/opencase_report/{opencase_report}",
* "add-form" = "/opencase/reporting/opencase_report/add",
* "edit-form" = "/opencase/reporting/opencase_report/{opencase_report}/edit",
* "delete-form" = "/opencase/reporting/opencase_report/{opencase_report}/delete",
* "collection" = "/opencase/reporting/opencase_report"
* }
* )
*/
class OpenCaseReport extends ConfigEntityBase implements OpenCaseReportInterface {
/**
* The OpenCase Report ID.
*
* @var string
*/
protected $id;
/**
* The OpenCase Report label.
*
* @var string
*/
protected $label;
}

View File

@ -0,0 +1,13 @@
<?php
namespace Drupal\opencase_reporting\Entity;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
/**
* Provides an interface for defining OpenCase Report entities.
*/
interface OpenCaseReportInterface extends ConfigEntityInterface {
// Add get/set methods for your configuration properties here.
}

View File

@ -0,0 +1,53 @@
<?php
namespace Drupal\opencase_reporting\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
/**
* Builds the form to delete OpenCase Report entities.
*/
class OpenCaseReportDeleteForm extends EntityConfirmFormBase {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete %name?', ['%name' => $this->entity->label()]);
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.opencase_report.collection');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message(
$this->t('content @type: deleted @label.',
[
'@type' => $this->entity->bundle(),
'@label' => $this->entity->label(),
]
)
);
$form_state->setRedirectUrl($this->getCancelUrl());
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace Drupal\opencase_reporting\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
/**
* Class OpenCaseReportForm.
*/
class OpenCaseReportForm extends EntityForm {
/**
* {@inheritdoc}
*/
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$opencase_report = $this->entity;
$form['label'] = [
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#maxlength' => 255,
'#default_value' => $opencase_report->label(),
'#description' => $this->t("Label for the OpenCase Report."),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#default_value' => $opencase_report->id(),
'#machine_name' => [
'exists' => '\Drupal\opencase_reporting\Entity\OpenCaseReport::load',
],
'#disabled' => !$opencase_report->isNew(),
];
/* You will need additional form elements for your custom properties. */
return $form;
}
/**
* {@inheritdoc}
*/
public function save(array $form, FormStateInterface $form_state) {
$opencase_report = $this->entity;
$status = $opencase_report->save();
switch ($status) {
case SAVED_NEW:
drupal_set_message($this->t('Created the %label OpenCase Report.', [
'%label' => $opencase_report->label(),
]));
break;
default:
drupal_set_message($this->t('Saved the %label OpenCase Report.', [
'%label' => $opencase_report->label(),
]));
}
$form_state->setRedirectUrl($opencase_report->toUrl('collection'));
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace Drupal\opencase_reporting;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Entity\Routing\AdminHtmlRouteProvider;
use Symfony\Component\Routing\Route;
/**
* Provides routes for OpenCase Report entities.
*
* @see Drupal\Core\Entity\Routing\AdminHtmlRouteProvider
* @see Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider
*/
class OpenCaseReportHtmlRouteProvider extends AdminHtmlRouteProvider {
/**
* {@inheritdoc}
*/
public function getRoutes(EntityTypeInterface $entity_type) {
$collection = parent::getRoutes($entity_type);
// Provide your custom entity routes here.
return $collection;
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Drupal\opencase_reporting;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
/**
* Provides a listing of OpenCase Report entities.
*/
class OpenCaseReportListBuilder extends ConfigEntityListBuilder {
/**
* {@inheritdoc}
*/
public function buildHeader() {
$header['label'] = $this->t('OpenCase Report');
$header['id'] = $this->t('Machine name');
return $header + parent::buildHeader();
}
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
$row['label'] = $entity->label();
$row['id'] = $entity->id();
// You probably want a few more properties here...
return $row + parent::buildRow($entity);
}
}

View File

@ -1,29 +0,0 @@
<?php
namespace Drupal\opencase_reporting\Plugin\Block;
use Drupal\opencase\EntityTypeRelations;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Link;
use Drupal\Core\Url;
/**
* Provides a block for loading, saving and creating report presets.
*
* @Block(
* id = "opencase_reporting_presets",
* admin_label = @Translation("OpenCase Reporting Presets"),
* )
*/
class Presets extends BlockBase {
/**
* {@inheritdoc}
*/
public function build() {
return array(
'#presets' => array(array('title'=>'me and you', 'basis'=>'actors', 'filter'=>'&f%5B0%5D=actor_type%3Afat&f%5B1%5D=created%3A2018-09'), array('title'=>'them', 'basis'=>'actors')),
'#theme' => 'opencase_reporting_presets'
);
}
}