Example Plugin

In Neos you can enrich your nodes with PHP. In this example you will primarily see how to link PHP scripts to your node and output them in the html template. (If you want to see how to link Fusion and PHP look at Example Eel Helper) I'm also testing how to manipulate the repositories of Neos with PHP.  I read the first name, last name and user name and try to save the new data. This way you can also reset a user's password. But please make sure that I am still working on this example at the moment.

IMPORTANT: This article deals with the topic in fluid. Fluid is no longer best practice. We are working on rewriting the article in AFX.

Get Username Username
getFirstName (before set property): First name Last name
getFirstName (after set property): Franz Last name

Look what's behind it:

# Example Plugin
'Neos.Neos:Plugin': true
label: 'Example Plugin'
icon: 'icon-list'

prototype(Arsors.Neos:ExamplePlugin) < prototype(Neos.Neos:Plugin) {

package = 'Arsors.Neos'
controller = 'ExamplePlugin'
action = 'index'


namespace Arsors\Neos\Controller;

use Neos\Flow\Annotations as Flow;
use Neos\Flow\Mvc\Controller\ActionController;

use Neos\Flow\Security\Context;
use Neos\Neos\Domain\Service\UserService;
use Neos\Flow\Persistence\Doctrine\PersistenceManager;

use Neos\Flow\Security\Authentication\TokenInterface;

class ExamplePluginController extends ActionController
* @Flow\Inject
* @var Context
protected $securityContext;

* @Flow\Inject
* @var UserService
protected $userService;

* project overview page (index)
* @return mixed
public function indexAction() //TokenInterface $authenticationToken

// Get Account of User
$user = $this->userService->getCurrentUser();

// If User loggedin...
if ($user) {

// Set Account Identifier (Name to Login)
$username = $this->securityContext->getAccount();

// TODO Save setAccountIdentifier change
$authenticationToken = $this->securityContext->getAuthenticationTokens()['Neos.Neos:Backend'];
$this->view->assign('authenticationToken', $authenticationToken);

// Get Account Identifier (Name to Login)
$username = $this->userService->getUsername($user);
$this->view->assign('username', $username);

// Set Password
//$this->userService->setUserPassword($user, "YourPasswordGetHashedFromNeos!");

// Set FirstName
$firstNameBeforeSet = $user->getName()->getFirstName();
//$this->userService->updateUser($user); // Uncommend this line to save the new username, remember to escape $this->persistenceManager->persistAll(); as well
// Get FirstName & LastName
$firstNameAfterSet = $user->getName()->getFirstName();
$lastName = $user->getName()->getLastName();
$this->view->assign('firstNameBeforeSet', $firstNameBeforeSet." ".$lastName);
$this->view->assign('firstNameAfterSet', $firstNameAfterSet." ".$lastName);

// Give me rights to write, mofucker!!

} else {
// Return a failure
//$this->view->assign('user', "No User found!");

// Because you are probably not logged in I set the variable manually here so that an output takes place
$username = "Username";
$firstNameBeforeSet = "First name";
$firstNameAfterSet = "Franz";
$lastName = "Last name";

$this->view->assign('username', $username);
$this->view->assign('firstNameBeforeSet', $firstNameBeforeSet." ".$lastName);
$this->view->assign('firstNameAfterSet', $firstNameAfterSet." ".$lastName);




Get Username <span class="badge badge-secondary">{username}</span>
getFirstName (before set property): <span class="badge badge-secondary">{firstNameBeforeSet}</span><br />
getFirstName (after set property): <span class="badge badge-secondary">{firstNameAfterSet}</span><br />

Because a PHP script in Neos is prevented for security reasons we have to extend the user rights. So we allow Neos.Flow:Everybody (every visitor of the website/app) to access our script. Of course, user rights adaptations should be treated with caution.

      matcher: 'method(Arsors\Neos\Controller\ExamplePluginController->(.*)Action())'

        privilegeTarget: 'Arsors.Neos:ExamplePlugin'
        permission: GRANT

I have overwritten the default HTML-Template path of custom plugins in Neos here to have more of an association with a NodeType.

  requestFilter: 'isPackage("Arsors.Neos") && isController("ExamplePlugin") && isAction("index")'
    templatePathAndFilename: 'resource://Arsors.Neos/Private/Templates/NodeTypes/ExamplePlugin.html'
Last cache from 2021-05-13 at 22:12:00 (Example Eel Helper)