Skip to content
Snippets Groups Projects
Commit f04f0f8b authored by Steve Wirt's avatar Steve Wirt
Browse files

Issue #3406751 by swirt: Include an edit link in the table that lists sibling fields

parent eeec48a6
No related branches found
Tags 1.0.24
No related merge requests found
...@@ -334,36 +334,43 @@ trait CMDocumentConnectorTrait { ...@@ -334,36 +334,43 @@ trait CMDocumentConnectorTrait {
} }
/** /**
* Get the link to the field edit page using the entity.field_config.node_field_edit_form route. * Get link to edit page using entity.field_config.node_field_edit_form route.
* *
* @todo update this to account for other entity types supported by CM Document. * @todo Update to account for other entity types supported by CM Document.
* *
* @param string $type * @param string $type
* The entity type that the field is on.
* @param string $bundle * @param string $bundle
* The bundle that the field is on.
* @param string $machine * @param string $machine
* The machine name of the field.
* *
* @return \Drupal\Core\Link * @return \Drupal\Core\Link|string
* The link to the field instance edit page, or empty string if type not
* supported, or user has no access.
*/ */
public function getFieldEditLink(string $type, string $bundle, string $machine) : Link { public function getFieldEditLink(string $type, string $bundle, string $machine) {
// Set the $type_parameter_key based on the type. // Set the $type_parameter_key based on the type.
switch ($type) { switch ($type) {
case 'node': case 'node':
$type_parameter_key = 'node_type'; $type_parameter_key = 'node_type';
break; break;
case 'paragraph': case 'paragraph':
$type_parameter_key = 'paragraphs_type'; $type_parameter_key = 'paragraphs_type';
break; break;
} }
// Get the current path. // Get the current path.
$current_path = \Drupal::service('path.current')->getPath(); $current_path = \Drupal::service('path.current')->getPath();
if (!empty($type_parameter_key)) {
return Link::createFromRoute( $link = Link::createFromRoute(
$this->t('Edit'), $this->t('Edit'),
"entity.field_config.{$type}_field_edit_form", "entity.field_config.{$type}_field_edit_form",
[ [
"{$type_parameter_key}" => $bundle, $type_parameter_key => $bundle,
'field_config' => "{$type}.{$bundle}.{$machine}", 'field_config' => "{$type}.{$bundle}.{$machine}",
], ],
[ [
...@@ -371,8 +378,16 @@ trait CMDocumentConnectorTrait { ...@@ -371,8 +378,16 @@ trait CMDocumentConnectorTrait {
'destination' => $current_path, 'destination' => $current_path,
], ],
] ]
); );
if (!$link->getUrl()->access()) {
// User has no access to edit field, so output no link.
$link = '';
}
}
else {
$link = '';
}
return $link;
} }
} }
...@@ -158,12 +158,12 @@ class CmDocumentViewBuilder extends EntityViewBuilder { ...@@ -158,12 +158,12 @@ class CmDocumentViewBuilder extends EntityViewBuilder {
$add_on['table'] = [ $add_on['table'] = [
'#type' => 'table', '#type' => 'table',
'#header' => [ '#header' => [
$this->t("Field Name"), $this->t('Field Name'),
$this->t("Entity Type"), $this->t('Entity Type'),
$this->t("Bundle"), $this->t('Bundle'),
$this->t("Field Type"), $this->t('Field Type'),
$this->t("Documentation"), $this->t('Documentation'),
$this->t("Edit"), $this->t('Edit'),
], ],
'#rows' => $rows, '#rows' => $rows,
'#footer' => [["Total instances: $count", '', '', '', '', '']], '#footer' => [["Total instances: $count", '', '', '', '', '']],
...@@ -207,6 +207,7 @@ class CmDocumentViewBuilder extends EntityViewBuilder { ...@@ -207,6 +207,7 @@ class CmDocumentViewBuilder extends EntityViewBuilder {
'Bundle' => $bundle, 'Bundle' => $bundle,
'Field Type' => $fields[$field]['type'], 'Field Type' => $fields[$field]['type'],
'Document' => $this->getCmDocumentLink($entity_type, $bundle, $field), 'Document' => $this->getCmDocumentLink($entity_type, $bundle, $field),
'Edit' => $edit_link = $this->getFieldEditLink($entity_type, $bundle, $field),
]; ];
} }
} }
...@@ -216,7 +217,6 @@ class CmDocumentViewBuilder extends EntityViewBuilder { ...@@ -216,7 +217,6 @@ class CmDocumentViewBuilder extends EntityViewBuilder {
return $sibling_rows; return $sibling_rows;
} }
/** /**
* Gets a a table of field data for fields on a fieldable entity. * Gets a a table of field data for fields on a fieldable entity.
* *
...@@ -236,12 +236,12 @@ class CmDocumentViewBuilder extends EntityViewBuilder { ...@@ -236,12 +236,12 @@ class CmDocumentViewBuilder extends EntityViewBuilder {
$add_on['table'] = [ $add_on['table'] = [
'#type' => 'table', '#type' => 'table',
'#header' => [ '#header' => [
$this->t("Field Name"), $this->t('Field Name'),
$this->t("Field Machine Name"), $this->t('Field Machine Name'),
$this->t("Field Type"), $this->t('Field Type'),
$this->t("Description"), $this->t('Description'),
$this->t("Documentation"), $this->t('Documentation'),
$this->t("Edit"), $this->t('Edit'),
], ],
'#rows' => $rows, '#rows' => $rows,
'#footer' => [["Total fields: $count", '', '', '', '', '']], '#footer' => [["Total fields: $count", '', '', '', '', '']],
...@@ -278,14 +278,13 @@ class CmDocumentViewBuilder extends EntityViewBuilder { ...@@ -278,14 +278,13 @@ class CmDocumentViewBuilder extends EntityViewBuilder {
// It is not a field element, so bail out. // It is not a field element, so bail out.
continue; continue;
} }
$edit_link = $this->getFieldEditLink($type, $bundle, $machine);
$field_rows[] = [ $field_rows[] = [
'field _name' => $value->getLabel(), 'field _name' => $value->getLabel(),
'machine name' => $machine, 'machine name' => $machine,
'field_type' => $value->getType(), 'field_type' => $value->getType(),
'description' => $value->getDescription(), 'description' => $value->getDescription(),
'documentation' => $this->getCmDocumentLink($type, $bundle, $machine), 'documentation' => $this->getCmDocumentLink($type, $bundle, $machine),
'edit' => $edit_link->getUrl()->access() ? $edit_link : '', 'edit' => $this->getFieldEditLink($type, $bundle, $machine),
]; ];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment