Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Mar 5, 2022
1 parent 8c27d9a commit e607314
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/ExpandedSingles.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ class ExpandedSingles extends Plugin
// Public Properties
// =========================================================================

public string $schemaVersion = '1.0.0';
public bool $hasCpSettings = true;
public string $schemaVersion = '1.0.0';


// Traits
Expand Down Expand Up @@ -73,7 +73,7 @@ public function init(): void
// Only apply this for entries, and if there are any singles
if ($linkOption['refHandle'] === 'entry' && in_array('singles', $linkOption['sources'])) {
$modifiedSources = $this->getSinglesList()->createSectionedSinglesList($linkOption['sources']);

if ($modifiedSources) {
$event->linkOptions[$i]['sources'] = $modifiedSources;
}
Expand Down
16 changes: 10 additions & 6 deletions src/base/PluginTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@ trait PluginTrait
public static ExpandedSingles $plugin;


// Public Methods
// Static Methods
// =========================================================================

public function getSinglesList(): SinglesList
{
return $this->get('singlesList');
}

public static function log($message): void
{
Craft::getLogger()->log($message, Logger::LEVEL_INFO, 'expanded-singles');
Expand All @@ -37,6 +32,15 @@ public static function error($message): void
}


// Public Methods
// =========================================================================

public function getSinglesList(): SinglesList
{
return $this->get('singlesList');
}


// Private Methods
// =========================================================================

Expand Down
4 changes: 0 additions & 4 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,12 @@ class Settings extends Model
/**
* Expands the Singles link on the Entries page to list them like Channels
* and Structures.
*
* @var boolean
*/
public bool $expandSingles = true;

/**
* Automatically redirects to edit the Single Entry when clicking on the
* item in the sidebar.
*
* @var boolean
*/
public bool $redirectToEntry = false;

Expand Down
15 changes: 4 additions & 11 deletions src/services/SinglesList.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ class SinglesList extends Component

// Public Methods
// =========================================================================
/**
* Create a new singles list and replace the old one with it
*
*
*/

public function createSinglesList(RegisterElementSourcesEvent $event): void
{
$singles = [];
Expand All @@ -38,7 +34,7 @@ public function createSinglesList(RegisterElementSourcesEvent $event): void
// Create list of Singles
foreach ($singleSections as $single) {
$siteUrls = [];

foreach (Craft::$app->getSites()->getAllSiteIds() as $siteId) {
$siteEntry = Entry::find()
->siteId($siteId)
Expand All @@ -64,7 +60,7 @@ public function createSinglesList(RegisterElementSourcesEvent $event): void
'criteria' => [
'sectionId' => $single->id,
'editable' => false,
]
],
];
}
}
Expand All @@ -85,9 +81,6 @@ public function createSinglesList(RegisterElementSourcesEvent $event): void
* Create a new singles list and replace the old one with it. This is a slightly modified and shorthand version
* of `createSinglesList`, and is used for a Redactor field. This uses a simple array, and outputs an array of
* section:id combinations. This is because Redactor shows entries grouped by channels.
*
*
* @return array
*/
public function createSectionedSinglesList(array $sources): array
{
Expand All @@ -100,7 +93,7 @@ public function createSectionedSinglesList(array $sources): array
foreach ($sections as $section) {
if ($section->type === Section::TYPE_SINGLE) {
$sectionSiteSettings = $section->getSiteSettings();

foreach ($sites as $site) {
if (isset($sectionSiteSettings[$site->id]) && $sectionSiteSettings[$site->id]->hasUrls) {
$singles[] = 'single:' . $section->uid;
Expand Down

0 comments on commit e607314

Please sign in to comment.