0

I have created a module by customizing FlyViews module to fetch data from a third party API and render via a View. I have been successful in showing the data on a page but the data has merely one style, that is, fields. Now I want to render that content as nodes of a specific content type. That content type will be configured in the module's configuration page. Once I mention a content type, the content should be rendered as nodes of that type.

Even a hardcoded solution will work for me, but it would be nice if I could select the Show option (on Views configuration page) as Content, just as I can do for a regular View.

Edit

I have implemented the custom row plugin which is now visible in Views UI as Show option under Format. Selecting the option and saving shows the output from my plugin's render() method. This is as far as I could get without help. Any ideas how can I manipulate render() to actually render the external content as nodes/entities?

0
2

I would probably not go down the the road of using Views (or Ctools) plugins at all here. (And I'm a big fan as well as proponent of Ctools and it's plugin architecture.)

I would create a new entity type, or a dummy content type of a node, and then take over the loading of said entity/content type with hook_entity_load.

Why integrate with Views only, when you can integrate with Core instead, possibly even with less effort?

1
  • That way I would have to implement filter, sorting, pagination, etc. a lot of stuff which I can get from Views straight away! – Adee Dec 31 '13 at 13:05
2

Finally did it!

To achieve the result mentioned in the question, one can do the following:

  1. Create a module implementing Views row plugin. To do so,
    1. Implement hook_views_plugins() mentioning your row plugin. For help, see hook_views_plugins() documentation and its implementation in Views core class views_views_plugins.
    2. Implement the row plugin handler class. Create just a prototype for now.
    3. Mention the row plugin handler class in module.info file.
  2. In your plugin handler class,
    1. override option_definition() and options_form() methods to present the user with a text field to input node id of the node to clone. You may use entity_autocomplete field for the purpose. (If you wish to ask for a content type instead, you can use a content type drop down. I wish to use an existing node with tokens to replace with external content). Overrid validate() method if you wish to validate the input. For help, see Views core class views_plugin_row_node_view.
    2. Overrid render() method to load the node by id or create the node by content type, build the node view using node_view() function, and return the rendered HTML using drupal_render() function. See views_plugin_row_node_view::render() for reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.