Skip to content

Commit 5055089

Browse files
authored
Merge pull request #117 from ticktackk/develop
1.4.0
2 parents 155e043 + 81f25b5 commit 5055089

16 files changed

+602
-43
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
CHANGELOG
22
==========================
33

4+
## 1.4.0 (`1040070`)
5+
6+
- **New:** A new CLI command which will add class properties to entities similar to stock installation but with slight tweaks (#116)
7+
- **New:** Prefer template type in title over the type set in URL when creating template (#114)
8+
- **New:** Display style property group name and display order when viewing style properties (#113)
9+
- **New:** Allow using full width page in admin control panel (#79)
10+
- **Fix:** Creating class extension without any options provided throws unique add-on id required error (#115)
11+
412
## 1.3.8 (`1030870`)
513

614
- **Fix:** `XF\Api\Templater` error message when calling API endpoints

Cli/Command/ClassExtension.php

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,24 @@
22

33
namespace TickTackk\DeveloperTools\Cli\Command;
44

5-
use Closure;
65
use Symfony\Component\Console\Command\Command;
76
use Symfony\Component\Console\Helper\QuestionHelper;
87
use Symfony\Component\Console\Input\InputArgument;
98
use Symfony\Component\Console\Input\InputInterface;
109
use Symfony\Component\Console\Output\OutputInterface;
1110
use Symfony\Component\Console\Question\Question;
12-
use XF\Util\File;
13-
use XF\AddOn\AddOn;
11+
use XF\Cli\Command\AddOnActionTrait;
12+
use XF\Util\File as FileUtil;
1413
const USE_FUNCTION_PLACEHOLDER = true;
1514
use function str_replace;
1615

1716
/**
18-
* Class ClassExtension
19-
*
20-
* @package TickTackk\DeveloperTools\Cli\Command\AddOn
17+
* @version 1.4.0
2118
*/
2219
class ClassExtension extends Command
2320
{
21+
use AddOnActionTrait;
22+
2423
protected function configure() : void
2524
{
2625
$this
@@ -40,6 +39,8 @@ protected function configure() : void
4039
}
4140

4241
/**
42+
* @version 1.4.0
43+
*
4344
* @param InputInterface $input
4445
* @param OutputInterface $output
4546
*
@@ -55,15 +56,18 @@ protected function execute(InputInterface $input, OutputInterface $output) : ?in
5556
if (!$addOnId)
5657
{
5758
$question = new Question('<question>Enter the ID for the add-on:</question>');
58-
$question->setValidator($this->getAddOnQuestionFieldValidator('addon_id'));
5959
$addOnId = $helper->ask($input, $output, $question);
6060
$output->writeln('');
6161
}
6262

63-
$addOnObj = new AddOn($addOnId, \XF::app()->addOnManager());
63+
$addOnObj = $this->checkEditableAddOn($addOnId, $error);
64+
if (!$addOnObj)
65+
{
66+
$output->writeln('<error>' . $error . '</error>');
67+
return 1;
68+
}
6469

6570
$jsonPath = $addOnObj->getJsonPath();
66-
6771
if (!file_exists($jsonPath))
6872
{
6973
$output->writeln(sprintf('<error>The addon.json file must exist at %s.</error>', $jsonPath));
@@ -86,7 +90,7 @@ protected function execute(InputInterface $input, OutputInterface $output) : ?in
8690
$toClassPath = $addOnObj->getAddOnDirectory() . DIRECTORY_SEPARATOR . $fromClassPath;
8791
$outputPath = $toClassPath . '.php';
8892

89-
File::createDirectory(dirname($toClassPath), false);
93+
FileUtil::createDirectory(dirname($toClassPath), false);
9094

9195
if (!file_exists($outputPath))
9296
{
@@ -158,7 +162,7 @@ class {$className} extends XFCP_{$className}
158162
}
159163
TEMPLATE;
160164

161-
$written = File::writeFile($outputPath, $template, false);
165+
$written = FileUtil::writeFile($outputPath, $template, false);
162166
if ($written)
163167
{
164168
$output->writeln("Wrote class extension template to {$outputPath}");
@@ -206,28 +210,4 @@ protected function getCommonUseStatements() : string
206210
TEMPLATE;
207211

208212
}
209-
210-
/**
211-
* @param $key
212-
*
213-
* @return Closure
214-
*/
215-
protected function getAddOnQuestionFieldValidator($key) : callable
216-
{
217-
return function ($value) use ($key)
218-
{
219-
$addOn = \XF::em()->create('XF:AddOn');
220-
221-
$valid = $addOn->set($key, $value);
222-
if (!$valid)
223-
{
224-
$errors = $addOn->getErrors();
225-
if (isset($errors[$key]))
226-
{
227-
throw new \InvalidArgumentException($errors[$key]);
228-
}
229-
}
230-
return $value;
231-
};
232-
}
233213
}

0 commit comments

Comments
 (0)