Skip to content

Commit

Permalink
More clean up and formatting of files
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Delaney committed Jun 30, 2022
1 parent a42d068 commit 47cdae4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 70 deletions.
14 changes: 4 additions & 10 deletions src/Vocabulary.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Vocabulary plugin for Craft CMS 3.x or later
* Vocabulary plugin for Craft CMS 3.x or later.
*
* Vocabulary is the easiest way to create and manage your own glossary of terms in Craft CMS.
*
Expand All @@ -11,13 +11,13 @@
namespace delaneymethod\vocabulary;

use Craft;
use yii\base\Event;
use craft\base\Plugin;
use craft\services\Fields;
use craft\services\Plugins;
use craft\events\PluginEvent;
use craft\events\RegisterComponentTypesEvent;
use craft\services\Fields;
use craft\services\Plugins;
use delaneymethod\vocabulary\fields\Vocabulary as VocabularyField;
use yii\base\Event;

/**
* @author DelaneyMethod
Expand All @@ -26,9 +26,6 @@
*/
class Vocabulary extends Plugin
{
/**
* @var Vocabulary
*/
public static Vocabulary $plugin;

/**
Expand All @@ -46,9 +43,6 @@ class Vocabulary extends Plugin
*/
public $hasCpSection = false;

/**
* @return void
*/
public function init()
{
parent::init();
Expand Down
103 changes: 49 additions & 54 deletions src/controllers/VocabularyController.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Vocabulary plugin for Craft CMS 3.x or later
* Vocabulary plugin for Craft CMS 3.x or later.
*
* Vocabulary is the easiest way to create and manage your own glossary of terms in Craft CMS.
*
Expand All @@ -12,21 +12,21 @@
namespace delaneymethod\vocabulary\controllers;

use Craft;
use Throwable;
use yii\web\Response;
use yii\base\Exception;
use craft\fields\Table;
use craft\web\Controller;
use craft\models\Section;
use craft\elements\Entry;
use craft\fields\PlainText;
use yii\base\InvalidConfigException;
use craft\models\Section_SiteSettings;
use craft\errors\SiteNotFoundException;
use craft\errors\ElementNotFoundException;
use craft\errors\SectionNotFoundException;
use craft\errors\EntryTypeNotFoundException;
use craft\errors\SectionNotFoundException;
use craft\errors\SiteNotFoundException;
use craft\fields\PlainText;
use craft\fields\Table;
use craft\models\Section;
use craft\models\Section_SiteSettings;
use craft\web\Controller;
use delaneymethod\vocabulary\fields\Vocabulary as VocabularyField;
use Throwable;
use yii\base\Exception;
use yii\base\InvalidConfigException;
use yii\web\Response;

/**
* @author DelaneyMethod
Expand All @@ -46,7 +46,6 @@ class VocabularyController extends Controller
protected $allowAnonymous = true;

/**
* @return Response
* @throws Exception
*/
public function actionInstallExamples(): Response
Expand All @@ -64,7 +63,7 @@ public function actionInstallExamples(): Response

return $this->asJson([
'success' => $success,
'message' => $message
'message' => $message,
]);
} catch (Throwable $exception) {
$message = $exception->getMessage();
Expand All @@ -76,7 +75,6 @@ public function actionInstallExamples(): Response
}

/**
* @return bool
* @throws Throwable
*/
private function createFieldType(): bool
Expand Down Expand Up @@ -113,8 +111,8 @@ private function createFieldType(): bool
'initialRows' => '4',
'multiline' => '',
'placeholder' => null,
'uiMode' => 'normal'
]
'uiMode' => 'normal',
],
],
'new2' => [
'id' => null,
Expand All @@ -130,23 +128,23 @@ private function createFieldType(): bool
'heading' => 'Title',
'handle' => 'title',
'width' => '',
'type' => 'singleline'
'type' => 'singleline',
],
'col2' => [
'heading' => 'Body',
'handle' => 'body',
'width' => '',
'type' => 'multiline'
]
'type' => 'multiline',
],
],
'maxRows' => '',
'minRows' => ''
]
]
]
]
]
]
'minRows' => '',
],
],
],
],
],
],
]);

$success = Craft::$app->getFields()->saveField($field);
Expand All @@ -156,7 +154,6 @@ private function createFieldType(): bool
}

/**
* @return bool
* @throws SectionNotFoundException
* @throws SiteNotFoundException
* @throws Throwable
Expand All @@ -173,16 +170,16 @@ private function createExampleSection(): bool
'uriFormat' => '{slug}',
'enabledByDefault' => true,
'template' => 'glossary-example.twig',
'siteId' => Craft::$app->getSites()->getPrimarySite()->id
'siteId' => Craft::$app->getSites()->getPrimarySite()->id,
]);

$section = new Section([
'name' => 'Glossary Example',
'handle' => 'glossaryExample',
'type' => Section::TYPE_SINGLE,
'siteSettings' => [
$siteSettings
]
$siteSettings,
],
]);

$success = Craft::$app->getSections()->saveSection($section);
Expand All @@ -192,7 +189,6 @@ private function createExampleSection(): bool
}

/**
* @return bool
* @throws EntryTypeNotFoundException
* @throws InvalidConfigException
* @throws Throwable
Expand All @@ -216,7 +212,7 @@ private function createExampleEntryType(): bool
$fields = $tabs[0]->getFields();

$fields = array_unique(array_merge($fields, [
$field
$field,
]));

$tabs[0]->setFields($fields);
Expand All @@ -232,9 +228,8 @@ private function createExampleEntryType(): bool
}

/**
* Adds an A-Z example
* Adds an A-Z example.
*
* @return bool
* @throws Exception
* @throws Throwable
* @throws ElementNotFoundException
Expand All @@ -246,7 +241,8 @@ private function createExampleEntry(): bool
$entry = Entry::find()
->section('glossaryExample')
->slug('glossary-example')
->one();
->one()
;

if ($entry) {
// Always work with a clean surface
Expand All @@ -266,18 +262,18 @@ private function createExampleEntry(): bool
'glossaryItem' => [
[
'title' => 'Address Resolution Protocol',
'body' => 'A TCP/IP protocol to query MAC address of the target device by its IP address, so as to ensure right communication services.'
'body' => 'A TCP/IP protocol to query MAC address of the target device by its IP address, so as to ensure right communication services.',
], [
'title' => 'Adjacent Channel Selectivity',
'body' => 'A measurement of a receiver’s ability to process a desired signal while rejecting a strong signal in an adjacent channel.'
'body' => 'A measurement of a receiver’s ability to process a desired signal while rejecting a strong signal in an adjacent channel.',
], [
'title' => 'AIE',
'body' => 'Air Interface Encryption, an encryption method used in TETRA on the Air Interface signalling only (control signalling and user payload).'
'body' => 'Air Interface Encryption, an encryption method used in TETRA on the Air Interface signalling only (control signalling and user payload).',
], [
'title' => 'Air Interface',
'body' => 'In wireless communication, the air interface is the radio-based communication link between the mobile station and the active base station.'
]
]
'body' => 'In wireless communication, the air interface is the radio-based communication link between the mobile station and the active base station.',
],
],
];

$glossaries[] = $glossary;
Expand All @@ -291,15 +287,15 @@ private function createExampleEntry(): bool
'glossaryItem' => [
[
'title' => 'BS',
'body' => 'Base Station'
'body' => 'Base Station',
], [
'title' => 'Base Station',
'body' => 'In wireless communication, a base station is a wireless communication station installed at a fixed location and used as part of a two-way radio system.'
'body' => 'In wireless communication, a base station is a wireless communication station installed at a fixed location and used as part of a two-way radio system.',
], [
'title' => 'Bit Error Rate',
'body' => 'The number of received bits that have been altered due to noise, interference, and distortion, divided by the total number of transferred bits during a studied time interval locking. A measure of the receiver\'s ability to resist the strong interference signals.'
]
]
'body' => 'The number of received bits that have been altered due to noise, interference, and distortion, divided by the total number of transferred bits during a studied time interval locking. A measure of the receiver\'s ability to resist the strong interference signals.',
],
],
];

$glossaries[] = $glossary;
Expand All @@ -313,9 +309,9 @@ private function createExampleEntry(): bool
'glossaryItem' => [
[
'title' => 'Call Out',
'body' => 'Standardized paging and resource management method for TETRA systems.'
]
]
'body' => 'Standardized paging and resource management method for TETRA systems.',
],
],
];

$glossaries[] = $glossary;
Expand All @@ -329,7 +325,7 @@ private function createExampleEntry(): bool
$glossary['type'] = 'glossary';
$glossary['fields'] = [
'glossaryHeading' => $letter,
'glossaryItem' => []
'glossaryItem' => [],
];

$glossaries[] = $glossary;
Expand All @@ -339,7 +335,7 @@ private function createExampleEntry(): bool
$newBlocks['blocks'] = [];

foreach ($glossaries as $key => $glossary) {
$newBlocks['blocks']['new:' . ($key + 1)] = $glossary;
$newBlocks['blocks']['new:'.($key + 1)] = $glossary;
}

$existingBlocks = $entry->getFieldValue('vocabulary')->ids();
Expand All @@ -358,11 +354,10 @@ private function createExampleEntry(): bool
}

/**
* @return bool
* @throws Exception
*/
private function createExampleTemplates(): bool
{
return copy(Craft::$app->getPlugins()->getPlugin('vocabulary')->getBasePath() . '/templates/glossary-example.twig', Craft::$app->getPath()->getSiteTemplatesPath() . '/glossary-example.twig');
return copy(Craft::$app->getPlugins()->getPlugin('vocabulary')->getBasePath().'/templates/glossary-example.twig', Craft::$app->getPath()->getSiteTemplatesPath().'/glossary-example.twig');
}
}
9 changes: 4 additions & 5 deletions src/fields/Vocabulary.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Vocabulary plugin for Craft CMS 3.x or later
* Vocabulary plugin for Craft CMS 3.x or later.
*
* Vocabulary is the easiest way to create and manage your own glossary of terms in Craft CMS.
*
Expand All @@ -11,11 +11,11 @@
namespace delaneymethod\vocabulary\fields;

use Craft;
use yii\base\Exception;
use craft\fields\Matrix;
use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use yii\base\Exception;

/**
* @author DelaneyMethod
Expand All @@ -27,15 +27,14 @@ class Vocabulary extends Matrix
/**
* Returns the display name of this class.
*
* @return string The display name of this class.
* @return string the display name of this class
*/
public static function displayName(): string
{
return Craft::t('vocabulary', 'Vocabulary');
}

/**
* @return string
* @throws LoaderError
* @throws RuntimeError
* @throws SyntaxError
Expand All @@ -44,7 +43,7 @@ public static function displayName(): string
public function getSettingsHtml(): string
{
return Craft::$app->getView()->renderTemplate('vocabulary/_components/fields/Vocabulary_settings', [
'field' => $this
'field' => $this,
]);
}
}
2 changes: 1 addition & 1 deletion src/translations/en/vocabulary.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* Vocabulary plugin for Craft CMS 3.x or later
* Vocabulary plugin for Craft CMS 3.x or later.
*
* Vocabulary is the easiest way to create and manage your own glossary of terms in Craft CMS.
*
Expand Down

0 comments on commit 47cdae4

Please sign in to comment.