diff --git a/src/CMDocumentConnectorTrait.php b/src/CMDocumentConnectorTrait.php index 972d5a03733cfa00539f22bd007afe87ebd7fc70..3e5fe3a0ca7708c2e8842021da987c7a357a4490 100644 --- a/src/CMDocumentConnectorTrait.php +++ b/src/CMDocumentConnectorTrait.php @@ -333,4 +333,46 @@ trait CMDocumentConnectorTrait { } } + /** + * Get the link to the field edit page using the entity.field_config.node_field_edit_form route. + * + * @todo update this to account for other entity types supported by CM Document. + * + * @param string $type + * @param string $bundle + * @param string $machine + * + * @return \Drupal\Core\Link + */ + public function getFieldEditLink(string $type, string $bundle, string $machine) : Link { + + // Set the $type_parameter_key based on the type. + switch ($type) { + case 'node': + $type_parameter_key = 'node_type'; + break; + case 'paragraph': + $type_parameter_key = 'paragraphs_type'; + break; + } + + // Get the current path. + $current_path = \Drupal::service('path.current')->getPath(); + + return Link::createFromRoute( + $this->t('Edit'), + "entity.field_config.{$type}_field_edit_form", + [ + "{$type_parameter_key}" => $bundle, + 'field_config' => "{$type}.{$bundle}.{$machine}", + ], + [ + 'query' => [ + 'destination' => $current_path, + ], + ] + ); + + } + } diff --git a/src/CmDocumentViewBuilder.php b/src/CmDocumentViewBuilder.php index 2ca4da5a4da8bb80f8596f52169b95b82f97ffcd..b76f9d7d7b7bec852cdd016af43d15946177878d 100644 --- a/src/CmDocumentViewBuilder.php +++ b/src/CmDocumentViewBuilder.php @@ -163,9 +163,10 @@ class CmDocumentViewBuilder extends EntityViewBuilder { $this->t("Bundle"), $this->t("Field Type"), $this->t("Documentation"), + $this->t("Edit"), ], '#rows' => $rows, - '#footer' => [["Total instances: $count", '', '', '', '']], + '#footer' => [["Total instances: $count", '', '', '', '', '']], '#empty' => $this->t('No table content found.'), '#caption' => $this->t("Sibling instances of field @field.", ['@field' => $field]), '#attributes' => [ @@ -240,9 +241,10 @@ class CmDocumentViewBuilder extends EntityViewBuilder { $this->t("Field Type"), $this->t("Description"), $this->t("Documentation"), + $this->t("Edit"), ], '#rows' => $rows, - '#footer' => [["Total fields: $count", '', '', '', '']], + '#footer' => [["Total fields: $count", '', '', '', '', '']], '#empty' => $this->t('No table content found.'), '#caption' => $this->t("Fields that appear on @type @bundle", ['@type' => $type, '@bundle' => $bundle]), '#attributes' => [ @@ -272,16 +274,18 @@ class CmDocumentViewBuilder extends EntityViewBuilder { $bundle = $cm_document->getDocumentedEntityParameter('bundle'); $fields = $cm_document->entityFieldManager->getFieldDefinitions($type, $bundle); foreach ($fields as $machine => $value) { - if (!$this->isField($machine)) { - // It is not a field element, so bail out. - continue; - } + if (!$this->isField($machine)) { + // It is not a field element, so bail out. + continue; + } + $edit_link = $this->getFieldEditLink($type, $bundle, $machine); $field_rows[] = [ 'field _name' => $value->getLabel(), 'machine name' => $machine, 'field_type' => $value->getType(), 'description' => $value->getDescription(), 'documentation' => $this->getCmDocumentLink($type, $bundle, $machine), + 'edit' => $edit_link->getUrl()->access() ? $edit_link : '', ]; }