Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Link to operation #653

Merged
merged 3 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 129 additions & 0 deletions config/views.view.db_links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,57 @@ display:
multi_type: separator
separator: ', '
field_api_classes: false
linkcheckerlink_group_entity_label:
id: linkcheckerlink_group_entity_label
table: linkchecker_link
field: linkcheckerlink_group_entity_label
relationship: none
group_type: group
admin_label: ''
entity_type: linkcheckerlink
plugin_id: linkcheckerlink_group_entity_label
label: 'Operation / Cluster'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
link_to_entity: 1
linkcheckerlink_page_entity_label:
id: linkcheckerlink_page_entity_label
table: linkchecker_link
Expand Down Expand Up @@ -460,6 +511,15 @@ display:
date_format: medium
custom_date_format: ''
timezone: ''
tooltip:
date_format: ''
custom_date_format: ''
time_diff:
enabled: false
future_format: '@interval hence'
past_format: '@interval ago'
granularity: 2
refresh: 60
group_column: value
group_columns: { }
group_rows: true
Expand Down Expand Up @@ -1172,6 +1232,15 @@ display:
date_format: medium
custom_date_format: ''
timezone: ''
tooltip:
date_format: ''
custom_date_format: ''
time_diff:
enabled: false
future_format: '@interval hence'
past_format: '@interval ago'
granularity: 2
refresh: 60
group_column: value
group_columns: { }
group_rows: true
Expand Down Expand Up @@ -1830,6 +1899,57 @@ display:
multi_type: separator
separator: ', '
field_api_classes: false
linkcheckerlink_group_entity_label:
id: linkcheckerlink_group_entity_label
table: linkchecker_link
field: linkcheckerlink_group_entity_label
relationship: none
group_type: group
admin_label: ''
entity_type: linkcheckerlink
plugin_id: linkcheckerlink_group_entity_label
label: 'Operation / Cluster'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
link_to_entity: 1
linkcheckerlink_page_entity_label:
id: linkcheckerlink_page_entity_label
table: linkchecker_link
Expand Down Expand Up @@ -2067,6 +2187,15 @@ display:
date_format: medium
custom_date_format: ''
timezone: ''
tooltip:
date_format: ''
custom_date_format: ''
time_diff:
enabled: false
future_format: '@interval hence'
past_format: '@interval ago'
granularity: 2
refresh: 60
group_column: value
group_columns: { }
group_rows: true
Expand Down
8 changes: 8 additions & 0 deletions html/modules/custom/hr_paragraphs/hr_paragraphs.module
Original file line number Diff line number Diff line change
Expand Up @@ -2468,4 +2468,12 @@ function hr_paragraphs_views_data_alter(array &$data) {
'id' => 'linkchecker_link_active_revisions',
],
];

$data['linkchecker_link']['linkcheckerlink_group_entity_label'] = [
'field' => [
'title' => t('Group entity label'),
'help' => t('The label of the entity that is related to the file.'),
'id' => 'linkcheckerlink_group_entity_label',
],
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

namespace Drupal\hr_paragraphs\Plugin\views\field;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityMalformedException;
use Drupal\Core\Entity\Exception\UndefinedLinkTemplateException;
use Drupal\Core\Form\FormStateInterface;
use Drupal\group\Entity\GroupRelationship;
use Drupal\linkchecker\LinkCheckerLinkInterface;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;

/**
* Field handler that builds the group entity label for the linkchecker_link.
*
* @ingroup views_field_handlers
*
* @ViewsField("linkcheckerlink_group_entity_label")
*/
class LinkcheckerLinkGroupEntityLabel extends FieldPluginBase {

/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['link_to_entity'] = ['default' => FALSE];
return $options;
}

/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['link_to_entity'] = [
'#title' => $this->t('Link to entity'),
'#description' => $this->t('Make entity label a link to entity page.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['link_to_entity']),
];
parent::buildOptionsForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
public function query() {
}

/**
* {@inheritdoc}
*/
public function render(ResultRow $values) {
$linkchecker_link = $this->getEntity($values);

if (!$linkchecker_link instanceof LinkCheckerLinkInterface) {
return '';
}

if (!$linkchecker_link->hasField('entity_id')) {
return '';
}

if ($linkchecker_link->get('entity_id')->isEmpty()) {
return '';
}

$linked_entity = $linkchecker_link->get('entity_id')->entity;

if (!$linked_entity instanceof EntityInterface) {
return '';
}

while ($linked_entity->getEntityTypeId() === 'paragraph' && $linked_entity->getParentEntity() !== NULL) {
$linked_entity = $linked_entity->getParentEntity();
}

$parent_entity = $linked_entity;

// Get group.
$group_content_array = GroupRelationship::loadByEntity($linked_entity);
$group_content = reset($group_content_array);
if ($group_content) {
$parent_entity = $group_content->getGroup();
}

if (!empty($this->options['link_to_entity'])) {
try {
$this->options['alter']['url'] = $parent_entity->toUrl();
$this->options['alter']['make_link'] = TRUE;
}
catch (UndefinedLinkTemplateException $e) {
$this->options['alter']['make_link'] = FALSE;
}
catch (EntityMalformedException $e) {
$this->options['alter']['make_link'] = FALSE;
}
}

return $this->sanitizeValue($parent_entity->label());
}

}