Skip to content

Commit

Permalink
Merge pull request #12 from punktDeForks/task/flow-6-compat
Browse files Browse the repository at this point in the history
TASK: Flow 6 compatibility
  • Loading branch information
skurfuerst committed Nov 14, 2019
2 parents d2cf451 + 8bbe679 commit 5fa5425
Show file tree
Hide file tree
Showing 19 changed files with 175 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Aop\JoinPointInterface;
use Neos\FluidAdaptor\View\Exception\InvalidTemplateResourceException;
use Neos\Fusion\FusionObjects\Helpers\FluidView;

/**
* When using CrudForms in Fusion (NOT in a Neos Plugin); but directly Fusion & Flow; the partial path overriding
Expand Down Expand Up @@ -34,7 +35,7 @@ public function getPartialPathAndFilenameWithFallback(JoinPointInterface $joinPo
try {
return $joinPoint->getAdviceChain()->proceed($joinPoint);
} catch (InvalidTemplateResourceException $e) {
/* @var $fluidView \Neos\Fusion\FusionObjects\Helpers\FluidView */
/* @var FluidView $fluidView */
$fluidView = $joinPoint->getProxy();

$partialRootPathBefore = $fluidView->getPartialRootPath();
Expand Down
38 changes: 23 additions & 15 deletions Classes/Command/CrudGeneratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
namespace Sandstorm\CrudForms\Command;


use Neos\Flow\Package\Exception\UnknownPackageException;
use Neos\Flow\Package\Package;
use Neos\Flow\Package\PackageManager;
use Neos\FluidAdaptor\Exception;
use Neos\Utility\Exception\FilesException;
use Neos\Utility\Files;
use Neos\FluidAdaptor\View\StandaloneView;
use Neos\Flow\Annotations as Flow;
Expand All @@ -14,7 +18,7 @@ class CrudGeneratorService

/**
* @Flow\Inject
* @var \Neos\Flow\Package\PackageManagerInterface
* @var PackageManager
*/
protected $packageManager;

Expand All @@ -23,7 +27,6 @@ class CrudGeneratorService
*/
protected $generatedFiles = array();


/**
* Generate a controller with the given name for the given package
*
Expand All @@ -33,6 +36,9 @@ class CrudGeneratorService
* @param string $modelClassName The name of the model to base the controler on
* @param boolean $overwrite Overwrite any existing files?
* @return array An array of generated filenames
* @throws UnknownPackageException
* @throws Exception
* @throws FilesException
*/
public function generateCrudController($packageKey, $subpackage, $controllerName, $modelClassName, $overwrite = FALSE)
{
Expand All @@ -57,7 +63,7 @@ public function generateCrudController($packageKey, $subpackage, $controllerName

$fileContent = $view->render();

$subpackagePath = $subpackage != '' ? $subpackage . '/' : '';
$subpackagePath = $subpackage !== '' ? $subpackage . '/' : '';
$controllerFilename = $controllerClassName . '.php';

$controllerPath = $this->getNamespaceBaseDirectory($packageKey) . $subpackagePath . 'Controller/';
Expand All @@ -75,8 +81,11 @@ public function generateCrudController($packageKey, $subpackage, $controllerName
* @param string $subpackage An optional subpackage name
* @param string $controllerName The name of the new controller
* @param string $modelClassName The name of the model to base the controler on
* @param $actionName
* @param boolean $overwrite Overwrite any existing files?
* @return array An array of generated filenames
* @throws Exception
* @throws FilesException
*/
public function generateCrudAction($packageKey, $subpackage, $controllerName, $modelClassName, $actionName, $overwrite = FALSE)
{
Expand All @@ -92,7 +101,7 @@ public function generateCrudAction($packageKey, $subpackage, $controllerName, $m

$fileContent = '{namespace crud=Sandstorm\CrudForms\ViewHelpers}' . chr(10) . $view->render();

$subpackagePath = $subpackage != '' ? $subpackage . '/' : '';
$subpackagePath = $subpackage !== '' ? $subpackage . '/' : '';
$this->generateFile('resource://' . $packageKey . '/Private/Templates/' . $subpackagePath . $controllerName . '/' . $actionName . '.html', $fileContent, $overwrite);

return $this->generatedFiles;
Expand All @@ -106,14 +115,15 @@ public function generateCrudAction($packageKey, $subpackage, $controllerName, $m
* @param string $fileContent
* @param boolean $force
* @return void
* @throws FilesException
*/
protected function generateFile($targetPathAndFilename, $fileContent, $force = FALSE)
{
if (!is_dir(dirname($targetPathAndFilename))) {
\Neos\Utility\Files::createDirectoryRecursively(dirname($targetPathAndFilename));
Files::createDirectoryRecursively(dirname($targetPathAndFilename));
}

if (substr($targetPathAndFilename, 0, 11) === 'resource://') {
if (strpos($targetPathAndFilename, 'resource://') === 0) {
list($packageKey, $resourcePath) = explode('/', substr($targetPathAndFilename, 11), 2);
$relativeTargetPathAndFilename = $packageKey . '/Resources/' . $resourcePath;
} elseif (strpos($targetPathAndFilename, 'Tests') !== FALSE) {
Expand All @@ -122,24 +132,22 @@ protected function generateFile($targetPathAndFilename, $fileContent, $force = F
$relativeTargetPathAndFilename = substr($targetPathAndFilename, strrpos(substr($targetPathAndFilename, 0, strpos($targetPathAndFilename, 'Classes/') - 1), '/') + 1);
}

if (!file_exists($targetPathAndFilename) || $force === TRUE) {
if ($force === true || !file_exists($targetPathAndFilename)) {
file_put_contents($targetPathAndFilename, $fileContent);
$this->generatedFiles[] = 'Created .../' . $relativeTargetPathAndFilename;
} else {
$this->generatedFiles[] = 'Omitted .../' . $relativeTargetPathAndFilename;
}
}

/**
* @param $packageKey
* @return string
* @throws UnknownPackageException
*/
private function getNamespaceBaseDirectory($packageKey)
{
$package = $this->packageManager->getPackage($packageKey);

if (in_array('psr-4', $package->getAutoloadTypes())) {
// WORKAROUND to support PSR4 properly
return Files::getNormalizedPath($package->getPackagePath() . '/Classes/');
} else {
return $package->getClassesNamespaceEntryPath();
}

return Files::getNormalizedPath($package->getPackagePath() . '/Classes/');
}
}
14 changes: 10 additions & 4 deletions Classes/Command/CrudKickstartCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@

use Neos\Flow\Cli\CommandController;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Package\Exception\UnknownPackageException;
use Neos\Flow\Package\PackageManager;
use Neos\FluidAdaptor\Exception;
use Neos\Utility\Exception\FilesException;

class CrudKickstartCommandController extends CommandController
{


/**
* @Flow\Inject
* @var \Neos\Flow\Package\PackageManagerInterface
* @var PackageManager
*/
protected $packageManager;

/**
* @Flow\Inject
* @var \Sandstorm\CrudForms\Command\CrudGeneratorService
* @var CrudGeneratorService
*/
protected $crudGeneratorService;

Expand All @@ -27,8 +31,10 @@ class CrudKickstartCommandController extends CommandController
* @param string $packageKey The package key of the package for the new controller with an optional subpackage, (e.g. "MyCompany.MyPackage/Admin").
* @param string $controllerName The name for the new controller. This may also be a comma separated list of controller names.
* @param string $modelName The model class name. Either fully-qualified or assumed to be in $packageKey.
* @param boolean $override override generated classes?
* @return string
* @param bool $overwrite
* @throws UnknownPackageException
* @throws Exception
* @throws FilesException
* @see neos.kickstart:kickstart:commandcontroller
*/
public function crudControllerCommand($packageKey, $controllerName, $modelName, $overwrite = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion Classes/FieldGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ interface FieldGeneratorInterface
* @param object $context an arbitrary object which is available in all actions and nested functionality
* @return array<FormField> each key is a property name, each value a FormField object
*/
function generate($context);
public function generate($context);
}
2 changes: 1 addition & 1 deletion Classes/Helper/CollectionAdjustmentUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class CollectionAdjustmentUtility
{
static public function similarize(Collection $target, Collection $source)
public static function similarize(Collection $target, Collection $source)
{
foreach ($target as $element) {
if (!$source->contains($element)) {
Expand Down
4 changes: 2 additions & 2 deletions Classes/Property/TypeConverter/ExtendedDateTimeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function convertFrom($source, $targetType, array $convertedChildPropertie
}

return $result;
} else {
return parent::convertFrom($source, $targetType, $convertedChildProperties, $configuration);
}

return parent::convertFrom($source, $targetType, $convertedChildProperties, $configuration);
}
}
2 changes: 1 addition & 1 deletion Classes/ViewHelpers/AbstractDefinitionViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function getProperties($model, $context = null)
}

foreach (get_class_methods($model) as $methodName) {
if (substr($methodName, 0, 3) === 'get') {
if (strpos($methodName, 'get') === 0) {
$methodAnnotation = $this->reflectionService->getMethodAnnotation($model, $methodName, FormField::class);

if ($methodAnnotation) {
Expand Down
26 changes: 21 additions & 5 deletions Classes/ViewHelpers/FormDefinitionViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,36 @@
namespace Sandstorm\CrudForms\ViewHelpers;

use Neos\Flow\Annotations as Flow;
use Neos\FluidAdaptor\Core\ViewHelper\Exception;
use Sandstorm\CrudForms\Exception\MissingModelTypeException;

class FormDefinitionViewHelper extends AbstractDefinitionViewHelper
{

/**
* @param mixed $objects
* @param string $model the model class name
* @param object $context an arbitrary object which is available in all actions and nested functionality
* @return void
* @throws Exception
*/
public function render($object, $model, $context = null)
public function initializeArguments()
{
$this->registerArgument('object', 'object', 'object', true);
$this->registerArgument('model', 'string', 'the model class name', true);
$this->registerArgument('context', 'object', 'n arbitrary object which is available in all actions and nested functionality', false, null);
}

/**
* @return array
* @throws MissingModelTypeException
*/
public function render()
{
$object = $this->arguments['object'];
$model = $this->arguments['model'];
$context = $this->arguments['context'];

$fields = $this->getProperties($model, $context);

$fields = array_filter($fields, function ($element) {
$fields = array_filter($fields, static function ($element) {
return $element['visible'] && $element['visibleInForm'];
});

Expand Down
15 changes: 13 additions & 2 deletions Classes/ViewHelpers/Internal/ActionExistsViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,32 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Reflection\ReflectionService;
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
use Neos\FluidAdaptor\Core\ViewHelper\Exception;

class ActionExistsViewHelper extends AbstractViewHelper
{

/**
* @return void
* @throws Exception
*/
public function initializeArguments()
{
$this->registerArgument('action', 'string', 'action', true);
}

/**
* @Flow\Inject
* @var ReflectionService
*/
protected $reflectionService;

/**
* @param string $action
* @return bool
*/
public function render($action)
public function render()
{
$action = $this->arguments['action'];
$controllerObjectName = $this->controllerContext->getRequest()->getControllerObjectName();
return $this->reflectionService->hasMethod($controllerObjectName, $action . 'Action');
}
Expand Down
14 changes: 12 additions & 2 deletions Classes/ViewHelpers/Internal/FindObjectsForListingViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@
namespace Sandstorm\CrudForms\ViewHelpers\Internal;

use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
use Neos\FluidAdaptor\Core\ViewHelper\Exception;

class FindObjectsForListingViewHelper extends AbstractViewHelper
{
/**
* @return void
* @throws Exception
*/
public function initializeArguments()
{
$this->registerArgument('repository', 'string', 'Name of repository to use', true);
}

/**
* @param string $repository Name of repository to use
* @return string
*/
public function render($repository)
public function render()
{
$repository = $this->arguments['repository'];
if (strpos($repository, '::') === false) {
$repositoryName = $repository;
$methodName = 'findAll';
Expand Down
9 changes: 4 additions & 5 deletions Classes/ViewHelpers/Internal/Form/DateViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Sandstorm\CrudForms\ViewHelpers\Internal\Form;

use Neos\Utility\ObjectAccess;
use Neos\Utility\TypeHandling;
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;
use Neos\FluidAdaptor\Core\ViewHelper\Exception;
use Neos\FluidAdaptor\ViewHelpers\Form\TextfieldViewHelper;

class DateViewHelper extends TextfieldViewHelper
Expand All @@ -14,6 +12,7 @@ class DateViewHelper extends TextfieldViewHelper
* Initialize the arguments.
*
* @return void
* @throws Exception
* @api
*/
public function initializeArguments()
Expand All @@ -22,7 +21,7 @@ public function initializeArguments()
// HINT: we use a format compatible with the input type Date
$this->registerArgument('format', 'string', 'A Format string compatible with the DateTimeConverter.', FALSE, 'MULTIPLE');
}

/**
* Renders the textfield.
*
Expand All @@ -40,7 +39,7 @@ public function render()
return $content;
}

protected function getNameWithoutPrefix()
protected function getNameWithoutPrefix(): string
{
return parent::getNameWithoutPrefix() . '[date]';
}
Expand Down
15 changes: 13 additions & 2 deletions Classes/ViewHelpers/Internal/ObjectAccessViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Sandstorm\CrudForms\ViewHelpers\Internal;

use Neos\FluidAdaptor\Core\ViewHelper\Exception;
use Neos\Utility\ObjectAccess;
use Neos\FluidAdaptor\Core\ViewHelper\AbstractViewHelper;

Expand All @@ -13,10 +14,20 @@ class ObjectAccessViewHelper extends AbstractViewHelper
{

/**
* @param string $property
* @return void
* @throws Exception
*/
public function render($property)
public function initializeArguments()
{
$this->registerArgument('property', 'string', 'property', true);
}

/**
* @return mixed
*/
public function render()
{
$property = $this->arguments['property'];
$object = $this->renderChildren();
return ObjectAccess::getPropertyPath($object, $property);
}
Expand Down
3 changes: 3 additions & 0 deletions Classes/ViewHelpers/Internal/OptionalPartialViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class OptionalPartialViewHelper extends AbstractViewHelper
{
protected $escapeOutput = FALSE;

/**
* @return mixed|void
*/
public function render()
{
try {
Expand Down
Loading

0 comments on commit 5fa5425

Please sign in to comment.