Problem/Motivation

As #2300677: JSON:API POST/PATCH support for fully validatable config entities seems not to have lot of support we need to exclude ConfigEntity as rest resources thus helping contrib aka Rest UI with #2303369: Until #2300677 is fixed, show in REST UI that config entity resources are read-only

Proposed resolution

Make EntityResource abstract and add ContentEntityResource

abstract class EntityResource extends ResourceBase {
...
class ContentEntityResource extends EntityResource {

Remaining tasks

What more must be done to make this work?
Should class EntityDerivative made abstract too?

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

FileSize
10.48 KB

Just a rough start so far.

clemens.tolboom’s picture

clemens.tolboom’s picture

mglaman’s picture

Status: Active » Needs review
FileSize
9.23 KB

Re-roll of #1 to get it to apply again.

Status: Needs review » Needs work

The last submitted patch, 4: do_not_expose_config-2339815-4.patch, failed testing.

Wim Leers’s picture

Title: Do not expose config entities as EntityResource » Limit EntityResource to content entities, rather than them causing fatal errors
Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Needs issue summary update, +Contributed project blocker
+++ b/core/modules/rest/src/Plugin/Deriver/EntityDeriver.php
@@ -70,11 +72,17 @@ public function getDerivativeDefinitions($base_plugin_definition) {
+        // @todo Add support for config entities later, see
+        //   https://www.drupal.org/node/2300677.
+        if (!$entity_type instanceof ContentEntityType) {
+          continue;
+        }

Only this part really makes sense to me: just only handle content entities. Then config entity types won't get REST routes created for them. Which is all that is necessary I think? Why all the other stuff?

Attempting to improve the title based on my understanding of this issue. I'm certain it's not entirely accurate. Please clarify.

clemens.tolboom’s picture

Maybe we should decide on this issue or #2300677: JSON:API POST/PATCH support for fully validatable config entities first? Should or shouldn't we expose config entities?

Wim Leers’s picture

My understanding:

swentel’s picture

I think we can just close this one and fix the other :) (because it makes to me have rest support for config entities)

clemens.tolboom’s picture

I agree with @wim-leers for fixing this issue too to get rid of the errors. And this is about a 8.0.x bug

swentel’s picture

Hmm, k, that's fair. The other one will never land for 8.0.x indeed.

Wim Leers’s picture

Yep. But then we first need to understand how the current code can actually cause breakage. Or is this solely for the purpose of allowing the REST UI contrib module to have slightly cleaner code?

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

Can't we add some kind of config validation to never allow this kind of setting?

Wim Leers’s picture

Can't we add some kind of config validation to never allow this kind of setting?

Configuration doesn't have the concept of validation at all? We only have validation for importing: \Drupal\Core\Config\ConfigEvents::IMPORT_VALIDATE.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Wim Leers’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

#2724823: EntityResource: read-only (GET) support for configuration entities already fixed Limit EntityResource to content entities, rather than them causing fatal errors.

It added this:

  /**
   * {@inheritdoc}
   */
  public function availableMethods() {
    $methods = parent::availableMethods();
    if ($this->isConfigEntityResource()) {
      // Currently only GET is supported for Config Entities.
      // @todo Remove when supported https://www.drupal.org/node/2300677
      $unsupported_methods = ['POST', 'PUT', 'DELETE', 'PATCH'];
      $methods = array_diff($methods, $unsupported_methods);
    }
    return $methods;
  }

  /**
   * Checks if this resource is for a Config Entity.
   *
   * @return bool
   *   TRUE if the entity is a Config Entity, FALSE otherwise.
   */
  protected function isConfigEntityResource() {
    return $this->entityType instanceof ConfigEntityType;
  }