Skip to content

Commit

Permalink
Fixed linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
kepol committed Dec 2, 2023
1 parent 7cec726 commit 55dad8b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
7 changes: 6 additions & 1 deletion quant.install
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ function quant_update_9008() {
// Keep track of what gets saved.
$saved = [];
$installPath = \Drupal::service('extension.list.module')->getPath('quant') . '/config/install/';
$names = ['quant_metadata_file', 'quant_metadata_node', 'quant_metadata_redirect', 'quant_metadata_taxonomy'];
$names = [
'quant_metadata_file',
'quant_metadata_node',
'quant_metadata_redirect',
'quant_metadata_taxonomy'
];
foreach ($names as $name) {
// Only create if the view doesn't exist.
if (!View::load($name)) {
Expand Down
4 changes: 2 additions & 2 deletions quant.module
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ function quant_preprocess_views_view_table(&$variables) {
$rows = $variables['rows'];
foreach ($rows as $id => $row) {
// @fixme Show warning class when published status does not match.
//$variables['rows'][$id]['attributes']->addClass('messages');
//$variables['rows'][$id]['attributes']->addClass('messages--warning');
// $variables['rows'][$id]['attributes']->addClass('messages');
// $variables['rows'][$id]['attributes']->addClass('messages--warning');
}
}
}
25 changes: 18 additions & 7 deletions src/Plugin/views/field/QuantMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\FileInterface;
use Drupal\image\Entity\ImageStyle;
use Drupal\node\NodeInterface;
use Drupal\redirect\Entity\Redirect;
use Drupal\taxonomy\TermInterface;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Drupal\quant\Utility;
Expand Down Expand Up @@ -54,7 +58,14 @@ protected function defineOptions() {
$options = parent::defineOptions();

// @todo Remove `redirect_http_code` and `redirect_url` when view is not for redirects.
$options['quant_metadata'] = ['default' => ['url', 'published', 'content_timestamp', 'date_timestamp']];
$options['quant_metadata'] = [
'default' => [
'url',
'published',
'content_timestamp',
'date_timestamp'
]
];

return $options;
}
Expand Down Expand Up @@ -101,19 +112,19 @@ public function preRender(&$values) {
// Handle URLs based on entity type.
$url = '';
// Nodes and terms will have the langcode in their URLs.
if ($entity instanceof \Drupal\node\NodeInterface || $entity instanceof \Drupal\taxonomy\TermInterface) {
if ($entity instanceof NodeInterface || $entity instanceof TermInterface) {
$url = $entity->toUrl()->toString();
}
// Add the langcode for redirects when using multilingual prefixes.
elseif ($entity instanceof \Drupal\redirect\Entity\Redirect) {
elseif ($entity instanceof Redirect) {
$url = $entity->getSourceUrl();
if (Utility::usesLanguagePathPrefixes()) {
$url = '/' . $entity->language()->getId() . $url;
}
}
// Image files may have any number of image styles. Don't need to handle
// media entities as the underlying image files are covered here.
elseif ($entity instanceof \Drupal\file\FileInterface) {
elseif ($entity instanceof FileInterface) {
$url = $entity->createFileUrl();
// For images, add image styles.
foreach ($imageStyles as $style) {
Expand Down Expand Up @@ -209,7 +220,7 @@ public function render(ResultRow $values) {

// Gather the metadata for each URL.
$build = [];
$numUrls = count($this->metadata[$entity->id()]);
$numUrls = count($this->metadata[$entity->id()]);
foreach ($this->metadata[$entity->id()] as $url => $data) {

$items = [];
Expand All @@ -231,14 +242,14 @@ public function render(ResultRow $values) {
elseif ($metadataTypes[$optionKey] === 'boolean') {
$metadataValue = $metadataValue ? $this->t('Yes') : $this->t('No');
}
$items[] = ['#markup' => '<strong>' . $this->t($this->metadataOptions[$optionKey]) . ':</strong> ' . $metadataValue];
$items[] = ['#markup' => '<strong>' . $this->metadataOptions[$optionKey] . ':</strong> ' . $metadataValue];
}
}

// File entities can have multiple URLs so format these differently.
$data = [];
if ($numUrls > 1) {
$data['url'] = ['#markup' => '<strong>' . $this->t('URL') . ':</strong> ' . $url];
$data['url'] = ['#markup' => $this->t('<strong>URL:</strong> :url', [':url' => $url])];
}
$data['metadata'] = [
'#theme' => 'item_list',
Expand Down

0 comments on commit 55dad8b

Please sign in to comment.