Made published field configurable on forms, and made views respect permissions

This commit is contained in:
naomi 2021-09-13 14:15:02 +01:00
parent b1a8534d29
commit ac4e6eddd5
6 changed files with 31 additions and 4 deletions

View File

@ -208,6 +208,7 @@ class OCCase extends RevisionableContentEntityBase implements OCCaseInterface {
->setLabel(t('Publishing status')) ->setLabel(t('Publishing status'))
->setDescription(t('A boolean indicating whether the Case is published.')) ->setDescription(t('A boolean indicating whether the Case is published.'))
->setRevisionable(TRUE) ->setRevisionable(TRUE)
->setDisplayConfigurable("form", TRUE)
->setDefaultValue(TRUE); ->setDefaultValue(TRUE);
$fields['user_id'] = BaseFieldDefinition::create('entity_reference') $fields['user_id'] = BaseFieldDefinition::create('entity_reference')

View File

@ -240,11 +240,11 @@ class OCActivity extends RevisionableContentEntityBase implements OCActivityInte
'weight' => -3, 'weight' => -3,
]); ]);
// not currently in use. Will set view and form settings when ready
$fields['status'] = BaseFieldDefinition::create('boolean') $fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Publishing status')) ->setLabel(t('Publishing status'))
->setDescription(t('A boolean indicating whether the Activity is published.')) ->setDescription(t('A boolean indicating whether the Activity is published.'))
->setRevisionable(TRUE) ->setRevisionable(TRUE)
->setDisplayConfigurable('form', TRUE)
->setDefaultValue(TRUE); ->setDefaultValue(TRUE);
$fields['user_id'] = BaseFieldDefinition::create('entity_reference') $fields['user_id'] = BaseFieldDefinition::create('entity_reference')

View File

@ -213,11 +213,11 @@ class OCActor extends RevisionableContentEntityBase implements OCActorInterface
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type); $fields = parent::baseFieldDefinitions($entity_type);
// Currently not using this, but will add form and view settings when ready.
$fields['status'] = BaseFieldDefinition::create('boolean') $fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Publishing status')) ->setLabel(t('Publishing status'))
->setDescription(t('Whether this record is published.')) ->setDescription(t('Whether this record is published.'))
->setRevisionable(TRUE) ->setRevisionable(TRUE)
->setDisplayConfigurable("form", true)
->setDefaultValue(TRUE); ->setDefaultValue(TRUE);
// The name gets set on preSave, from the first middle and last // The name gets set on preSave, from the first middle and last

View File

@ -167,7 +167,14 @@ class OCEvent extends ContentEntityBase implements OCEventInterface {
->setDisplayConfigurable('view', TRUE) ->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE); ->setRequired(TRUE);
$fields['status']->setDescription(t('A boolean indicating whether the Event is published.')); $fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Publishing status'))
->setDescription(t('Whether this record is published.'))
->setRevisionable(TRUE)
->setDisplayConfigurable("form", true)
->setDefaultValue(TRUE);
$fields['created'] = BaseFieldDefinition::create('created') $fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created')) ->setLabel(t('Created'))

View File

@ -456,7 +456,12 @@ class OCOrganisation extends EditorialContentEntityBase implements OCOrganisatio
->setDisplayConfigurable('view', TRUE) ->setDisplayConfigurable('view', TRUE)
->setRequired(TRUE); ->setRequired(TRUE);
$fields['status']->setDescription(t('A boolean indicating whether the Organisation is published.')); $fields['status'] = BaseFieldDefinition::create('boolean')
->setLabel(t('Published'))
->setRevisionable(TRUE)
->setDisplayConfigurable("form", true)
->setDefaultValue(TRUE);
$fields['created'] = BaseFieldDefinition::create('created') $fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created')) ->setLabel(t('Created'))

View File

@ -98,6 +98,20 @@ function opencase_uninstall() {
} }
function opencase_views_pre_render($view) { function opencase_views_pre_render($view) {
if (!empty($view->result)) {
foreach ($view->result as $key => $result) {
if (empty($result->_entity)) {
continue;
}
$access = \Drupal::entityTypeManager()
->getAccessControlHandler($result->_entity->getEntityTypeId())
->access($result->_entity, 'view', NULL, TRUE);
if (!$access->isAllowed()) {
unset($view->result[$key]);
}
}
}
if (empty($view->result) && empty($view->exposed_input)) { if (empty($view->result) && empty($view->exposed_input)) {
$view->exposed_widgets = NULL; $view->exposed_widgets = NULL;
} }