You are here

public function NodeEntityBundleController::getFormInfoByUrl in Permissions by Term 8.2

Same name and namespace in other branches
  1. 8 src/Controller/NodeEntityBundleController.php \Drupal\permissions_by_term\Controller\NodeEntityBundleController::getFormInfoByUrl()

Return value

JsonResponse

1 string reference to 'NodeEntityBundleController::getFormInfoByUrl'
permissions_by_term.routing.yml in ./permissions_by_term.routing.yml
permissions_by_term.routing.yml

File

src/Controller/NodeEntityBundleController.php, line 72

Class

NodeEntityBundleController
Class NodeEntityBundleController

Namespace

Drupal\permissions_by_term\Controller

Code

public function getFormInfoByUrl() {
  $contentType = $this
    ->getContentType(\Drupal::request()->query
    ->get('url'));
  if ($contentType === NULL) {
    return new JsonResponse([]);
  }
  $fields = $this->entityFieldManager
    ->getFieldDefinitions('node', $contentType);
  $fieldNames = [];
  foreach ($fields as $field) {
    $fieldDefinitionSettings = $field
      ->getSettings();
    if (!empty($fieldDefinitionSettings['target_type']) && $fieldDefinitionSettings['target_type'] == 'taxonomy_term') {
      $fieldNames[] = $field
        ->getFieldStorageDefinition()
        ->getName();
    }
  }
  return new JsonResponse([
    'taxonomyRelationFieldNames' => $fieldNames,
    'permissions' => $this->nodeEntityBundleInfo
      ->getPermissions(),
  ]);
}