Expose admin/structure/contact/messages/{contact_message} as a path where view the submission.

Patch will

  • move current path to admin/structure/contact/messages/{contact_message}/edit
  • make name, subject & mail base fields configurable on display
  • add a 'view' operation - I've been thinking whether overriding the list builder would be a better idea or adding a 'link to entity' formatter on the subject, can be debated of course.

Comments

swentel created an issue. See original summary.

swentel’s picture

Status: Active » Needs review
StatusFileSize
new5.89 KB
swentel’s picture

Issue summary: View changes
StatusFileSize
new48.21 KB
new61.54 KB

Some screenshots

jibran’s picture

+1 to this. This could have some test love. Just a nitpick.

+++ b/contact_storage.module
@@ -93,12 +118,15 @@ function contact_storage_entity_type_alter(array &$entity_types) {
+  $entity_types['contact_message']->setHandlerClass('route_provider',  array('html' => 'Drupal\contact_storage\Entity\MessageRouteProvider'));

We can use class constant here.

swentel’s picture

StatusFileSize
new2.63 KB
new1.93 KB
new7.98 KB

tests only + basic fixes

Not yet included #4

swentel’s picture

Not sure why the test only patch passes, it fails 'nicely' locally. :)

andypost’s picture

  1. +++ b/contact_storage.module
    @@ -80,6 +82,29 @@ function contact_storage_entity_base_field_info(\Drupal\Core\Entity\EntityTypeIn
    + *  Implements hook_entity_base_field_info_alter().
    ...
    + *  Implements hook_entity_operation_alter().
    

    please remove extra spaces after * on next re-roll

  2. +++ b/src/Controller/MessageViewController.php
    @@ -0,0 +1,36 @@
    +    return 'View message';
    

    $this->t()

  3. +++ b/src/Entity/MessageRouteProvider.php
    @@ -0,0 +1,41 @@
    +    $route = (new Route('/admin/structure/contact/messages/{contact_message}'))
    

    Is that really needed after https://www.drupal.org/node/2593577

swentel’s picture

StatusFileSize
new7.97 KB
new880 bytes
berdir’s picture

Status: Needs review » Needs work
  1. +++ b/contact_storage.module
    @@ -80,6 +82,33 @@ function contact_storage_entity_base_field_info(\Drupal\Core\Entity\EntityTypeIn
    +  if ($entity->getEntityTypeId() == 'contact_message') {
    +    $operations['view'] = array(
    

    Should we check for view access here?

  2. +++ b/src/Controller/MessageViewController.php
    @@ -0,0 +1,36 @@
    +  public function view(EntityInterface $contact_message, $view_mode = 'full') {
    +    $build = parent::view($contact_message, $view_mode);
    +    return $build;
    +  }
    

    This is needed because of the variable matching, right? kinda annoying.

  3. +++ b/src/Controller/MessageViewController.php
    @@ -0,0 +1,36 @@
    +  public function title() {
    +    return 'View message';
    

    missing t() ?

  4. +++ b/src/Entity/MessageRouteProvider.php
    @@ -0,0 +1,41 @@
    + * @file
    + * Contains \Drupal\contact_storage\Entity\NodeRouteProvider.
    + */
    

    oops.

  5. +++ b/src/Entity/MessageRouteProvider.php
    @@ -0,0 +1,41 @@
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function getRoutes( EntityTypeInterface $entity_type) {
    +    $route_collection = new RouteCollection();
    

    would it be easier to get the other issue in first, so we get that automatically as soon as we have a canonical link template?

swentel’s picture

1. Ha, yes, that's probably a better idea (and how annoying is dreditor's context sometimes, I was looking at contact_storage_entity_base_field_info first hah - unless you're really talking about that one, then I'm missing something)
2. yeah, I cried a little :)
3. Oh yes, missed that
4. and 5.: oops haha, and yes, it might be easier to get that other one in first, makes this patch even smaller

Will look at them on monday or tuesday unless someone beats me to it.

berdir’s picture

1. Yes, the context there is confusing but that's not dreditor's fault, that's how it is in the diff. You understood it correctly I think :)
2. Thinking about this again, why not use _entity_view in the route?
3. Because if it's a static title, then we can also just put it in _title in the route?

dasjo’s picture

StatusFileSize
new0 bytes

attached is a simple reroll based on the latest 8.x-1.x

dasjo’s picture

StatusFileSize
new1.87 KB
berdir’s picture

Issue tags: +Needs tests
efrainh’s picture

#13 fixed the error i was getting when trying to view/edit a message using version 8.x-1.0-beta2:

The website encountered an unexpected error. Please try again later.

Drupal\Core\Entity\Exception\UndefinedLinkTemplateException: No link template 'canonical' found for the 'contact_message' entity type in Drupal\Core\Entity\Entity->toUrl() (line 219 of core/lib/Drupal/Core/Entity/Entity.php).
Drupal\Core\Entity\Entity->urlInfo()
content_translation_page_attachments(Array)
Drupal\Core\Render\MainContent\HtmlRenderer->invokePageAttachmentHooks(Array)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1)
Stack\StackedHttpKernel->handle(Object, 1, 1)
Drupal\Core\DrupalKernel->handle(Object)

But it doesn't add the new features planned on this issue:

make name, subject & mail base fields configurable on display
add a 'view' operation - I've been thinking whether overriding the list builder would be a better idea or adding a 'link to entity' formatter on the subject, can be debated of course.

berdir’s picture

Would also help with #2676552: File usage view breaks if an entity uses a file that has no canonical link template

@efraihn: While this would help with that problem, it's message that has to be fixed. Modules must check that an entity has a canonical link template before calling it.

thamas’s picture

These modifications are needed to make the module really cool. I was shocked to see it provides an "Edit" option but not a "View" one.

Thanks for all the work!

asrob’s picture

StatusFileSize
new6.02 KB

Combined patches -8 and -12 into a big one. Tested with 8.x-1.x-dev.

andypost’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Status: Needs review » Needs work

The last submitted patch, 18: 2634226-18.patch, failed testing.

The last submitted patch, 18: 2634226-18.patch, failed testing.

The last submitted patch, 18: 2634226-18.patch, failed testing.

The last submitted patch, 18: 2634226-18.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review
StatusFileSize
new5.58 KB
new1.26 KB

Reroll again - tests pass on my local machine.

Address point 1 from Berdir's review in #9.
Current patch also uses the static routing file, which obsoletes the points in the review regarding the controller, title callback and route providere.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Ok, lets just do this and clean up routes/controllers in the other issue to let them be generated.

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Couple of minor observations.

  1. +++ b/src/Controller/MessageViewController.php
    @@ -0,0 +1,36 @@
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function view(EntityInterface $contact_message, $view_mode = 'full') {
    +    $build = parent::view($contact_message, $view_mode);
    +    return $build;
    +  }
    

    This seems redundant? We can just defer to the parent here yeah?

  2. +++ b/src/Entity/MessageRouteProvider.php
    @@ -0,0 +1,41 @@
    + * Contains \Drupal\contact_storage\Entity\NodeRouteProvider.
    

    c/p error

berdir’s picture

1. The variable name needs to match. But not really sure why we actually need a custom controller, I think we can possibly remove the controller again when adding a default route provider.

swentel’s picture

Status: Needs work » Reviewed & tested by the community

My patch in #24 doesn't even have that controller anymore, or am I going nuts ?

larowlan’s picture

@swentel yeah you're right, I just reviewed the latest file listed in the issue summary, sorry.

Have hidden all the irrelevant stuff now.

larowlan’s picture

Credit update

  • larowlan committed 196ea17 on 8.x-1.x authored by swentel
    Issue #2634226 by swentel, dasjo, asrob, Berdir, larowlan, andypost,...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed
+++ b/contact_storage.routing.yml
@@ -1,6 +1,14 @@
+    _permission: 'administer contact forms'

I think we need to use entity access here instead?

Which already defers to 'administer contact forms'.

But in reality, I think we need a new permissions 'view contact messsages'.

But that should be a new follow-up - 99% of the sites I work on we'd give low-level admins access to submitted messages. But 'administer contact forms' is a protected permission (because field create/edit access).

So pushed this as-is, will create that follow-up.

larowlan’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.