Skip to content

Commit

Permalink
Merge pull request #6 from CuBoulder/issue/3
Browse files Browse the repository at this point in the history
Adds Article Syndication "read more" article list (v1.2)
  • Loading branch information
jcsparks authored Dec 10, 2024
2 parents 110a7bf + 619e16e commit f5355c3
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
65 changes: 64 additions & 1 deletion src/ArticleSyndication.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,60 @@
namespace Drupal\ucb_article_syndication;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\node\Entity\Node;
use Drupal\path_alias\AliasManagerInterface;
use Drupal\pathauto\PathautoState;
use Psr\Log\LoggerInterface;

/**
* The Article Syndication service contains functions used by the module.
*/
class ArticleSyndication {

/**
* The path alias at which the syndication article list should reside.
*/
const SYNDICATION_PATH = '/syndicate';

/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;

/**
* The path alias manager.
*
* @var \Drupal\path_alias\AliasManagerInterface
*/
protected $aliasManager;

/**
* The logger channel for this module.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;

/**
* Constructs the Article Syndication service.
*
* @param \Drupal\Core\Extension\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\path_alias\AliasManagerInterface $alias_manager
* The path alias manager.
* @param \Psr\Log\LoggerInterface $logger
* The logger channel for this module.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
public function __construct(
ConfigFactoryInterface $config_factory,
AliasManagerInterface $alias_manager,
LoggerInterface $logger
) {
$this->configFactory = $config_factory;
$this->aliasManager = $alias_manager;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -99,4 +132,34 @@ public function showSyndicationFields() {
->save();
}

/**
* Creates the syndication article list.
*
* The syndication article list is a special article list which allows
* category, audience, and unit term ids to be passed in as URL parameters.
* Its main use case is to be used as the "read more" page for the Campus
* News block.
*
* A new article list will be created only if a node doesn’t already exist at
* the same path.
*/
public function createSyndicationArticleList() {
$pathAlias = $this::SYNDICATION_PATH;
if (preg_match('/node\/(\d+)/', $this->aliasManager->getPathByAlias($pathAlias))) {
$this->logger->warning("A syndication article list wasn’t created because a node already exists at the path alias $pathAlias.");
}
else {
$node = Node::create([
'type' => 'ucb_article_list',
'title' => 'Article Results',
'path' => [
'alias' => $pathAlias,
'pathauto' => PathautoState::SKIP,
],
'body' => '',
]);
$node->enforceIsNew()->save();
}
}

}
4 changes: 3 additions & 1 deletion ucb_article_syndication.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ name: CU Boulder Article Syndication
description: Extends the article content type to add the taxonomies needed for article syndication.
core_version_requirement: ^10 || ^11
type: module
version: '1.1'
version: '1.2'
package: CU Boulder
dependencies:
- cu_boulder_content_types
- field
- node
- path_alias
- pathauto
- taxonomy
1 change: 1 addition & 0 deletions ucb_article_syndication.install
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
function ucb_article_syndication_install() {
$articleSyndication = \Drupal::service('ucb_article_syndication');
$articleSyndication->showSyndicationFields();
$articleSyndication->createSyndicationArticleList();
}
5 changes: 5 additions & 0 deletions ucb_article_syndication.services.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
services:
logger.channel.ucb_article_syndication:
parent: logger.channel_base
arguments: ['ucb_article_syndication']
ucb_article_syndication:
class: 'Drupal\ucb_article_syndication\ArticleSyndication'
arguments:
- '@config.factory'
- '@path_alias.manager'
- '@logger.channel.ucb_article_syndication'

0 comments on commit f5355c3

Please sign in to comment.