Ajax call in neos plugin

Hi guys,

I wrote a flow application which requires an ajax call (json response) and tried to transform it to an neos plugin, but I don’t know how to remove the layout from the ajax action response. Currently my ajax response contains the layout + my json response (e.g. <html><head>...</head><body>['json', 1, 2]</body></html>). Does somebody have an idea how to remove the layout? I found an article about how to render special formats, but this didn’t work for my plugin. I tried something like this:

json = TYPO3.TypoScript:Case {
        person {
                # I also failed to create an appropriate condition
                condition = true
                type = 'My.Package:Person.Vcard'
        }
}

prototype(My.Package:Person.Vcard) < prototype(TYPO3.TypoScript:Http.Message) {
        # Set the Content-Type header
        httpResponseHead {
                headers.Content-Type = 'text/x-vcard;charset=utf-8'
        }
        content = My.Package:Person.Plugin {
            package = 'My.Package:Person'
            controller = 'myController'
            action = 'ajax'
        }
}

My form (which is submitted via ajax) looks like this:

<f:form method="post" object="{image}" objectName="image"
        enctype="multipart/form-data" action="ajax" format="json">
       <f:form.upload property="resource" />
        <f:form.submit value="Upload"></f:form.submit>
     </f:form>

Action function signature:

public function ajaxAction(\TYPO3\Media\Domain\Model\Image $image)

I also tried to define a route which excludes neos, but in this case the parameter mapping didn’t work:

-
  uriPattern: '{node}/ajax.{@format}'
  defaults:
      '@package': 'My.Package:Person'
      '@controller': 'myController'
      '@action': 'ajax'
      '@format': 'json'
  routeParts:
    node:
      handler:    TYPO3\Neos\Routing\FrontendNodeRoutePartHandler

Is there any example plugin, from which I could learn how to do this kind of stuff? Any article?

The thing that i see directly is that the form and the routing configuration use the format ‘json’. Your fusion(ts2) code above uses the path ‘vcard’ which cannot work.

The format json makes the fusion(ts2) root-case use the path ‘json’ as entry point instead of ‘page’. See: https://github.com/neos/neos-development-collection/blob/master/TYPO3.Neos/Resources/Private/TypoScript/DefaultTypoScript.ts2

Thanks for paying attention.

The above snippet is from the documentation and was just slightly modified (condition, content). Thereby I missed to change vcard to json. I updated the snippet accordingly.

What happens if you replace the content in prototype(My.Package:Person.Vcard) with an example string? That way you can distinguish between wether the plugin or neos are guilty of adding the html code.

Yes that’s working.

If I use content = My.Package:Person.Plugin it seems like the parameter matching doesn’t work, because $image (or even a test string parameter) is unset in ajaxAction.

Would it help, if I publish the current state of my plugin on github?

Debug step by step …

  • first check that the plugin will return json without any arguments as you expect
  • then accept a simple string argument
  • and then try the property mapping

Did you see the documentation-parts: http://neos.readthedocs.io/en/stable/ExtendingNeos/CreatingAPlugin.html#converting-a-flow-package-into-a-neos-plugin and http://neos.readthedocs.io/en/stable/ExtendingNeos/CreatingAPlugin.html#linking-to-a-plugin
I think the thing you are missing is that you have to namespace the plugin arguments.

@mficzel Thank you for your help. I could not get it to work with the fusion approach, but with the “excluding neos”-route. Your hint about namespaces, have led me to think about property mapping with custom routes and this was the key.

If I finish my plugin, it will be available at https://github.com/drkTettnang/DRKTettnang.OperationHistory for all who have similar issues.