On drupal 6, at versioncontrol, I created a views plugin row for operations.

It was really needed specially when it was needed to combine several fields into one rss item field(i.e. description). Using fields to build RSS items make that really easy-

Here I will provide a generalization of the original code fro drupal 7, so it can be used for all types, hopefully it sounds like a good idea for maintainers.

Comments

marvil07’s picture

Assigned: marvil07 » Unassigned
Status: Active » Needs review
StatusFileSize
new12.23 KB
new6.47 KB

Here the patch, and I am also attaching a view that uses it to provide an example.

marvil07’s picture

Assigned: Unassigned » marvil07
Status: Needs review » Needs work

I am working to let the user customize the rss item guid and adding the method option_definition() as dereine suggested by IRC.

marvil07’s picture

Assigned: marvil07 » Unassigned
Status: Needs work » Needs review
StatusFileSize
new3.89 KB
new8.38 KB

Here a new patch. It includes:

  • Add option_definition implementation.
  • Let configure the RSS item guid.
marvil07’s picture

I forgot to update the view example, here it is :-)

tim.plunkett’s picture

Triggering the testbot.

dawehner’s picture

As you asked in irc, you could use the tokens of views, so you could use arguments automatically.

dawehner’s picture

+    static $row_index;
+    if (!isset($row_index)) {
+      $row_index = 0;
+    }
+

You can just use $view->row_index;

marvil07’s picture

Status: Needs review » Needs work

OK. Hopefully I'll be back at this before tomorrow.

Thanks for the feedback.

dawehner’s picture

+++ b/plugins/views_plugin_row_rss_fields.incundefined
@@ -0,0 +1,165 @@
+      if (isset($element['namespace'])) {
+        $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $element['namespace']);

You could use the same code like in views_plugin_row_node_rss::render(). There is some additional code for rdf namespaces.

+++ b/plugins/views_plugin_row_rss_fields.incundefined
@@ -0,0 +1,165 @@
+    if (empty($this->view->style_plugin) || !is_object($this->view->style_plugin) || empty($field_id)) {
+      return '';

Are these checks really required? I'm wondering whether you could just use $this->view->style_plugin->get_field directly.

marvil07’s picture

Status: Needs work » Needs review
StatusFileSize
new874 bytes
new8.78 KB

You can just use $view->row_index;

It seems like I could not do that. Let me explain:
The style plugin get_field() method actually calls style plugin rendered_fields() method, which makes the rendering of all fields and at the end of it, unset the row_index data member. So, after using the first time the views_plugin_row_rss_fields::get_field() method I end up without the variable.
Then I guess I can not use it.

You could use the same code like in views_plugin_row_node_rss::render(). There is some additional code for rdf namespaces.

I see, I have included it now, but a little modified, because this is a general row plugin, and since rss_namespaces data member is only on node object, I only do the general call.

Are these checks really required? I'm wondering whether you could just use $this->view->style_plugin->get_field directly.

I remember adding those checks to make it easy to validate(I can not remember an specific case when they are needed, but I think they are OK to be there).

tim.plunkett’s picture

Status: Needs review » Needs work
+++ b/plugins/views_plugin_row_rss_fields.incundefined
@@ -0,0 +1,174 @@
+ * Plugin which render an RSS item based on fields.

"Use a 3rd person verb to begin the description of a class", also "render" should be "renders".

+++ b/plugins/views_plugin_row_rss_fields.incundefined
@@ -0,0 +1,174 @@
+    $options['guid_field_options']['guid_field_is_permalink'] = array('default' => TRUE);

Needs 'bool' => TRUE as well

+++ b/plugins/views_plugin_row_rss_fields.incundefined
@@ -0,0 +1,174 @@
+      '#description' => t('The field that is going to be used as the RSS item pubDate for each row. It need to be in RFC 2822 format.'),

"It need to be" should be "It needs to be"

+++ b/plugins/views_plugin_row_rss_fields.incundefined
@@ -0,0 +1,174 @@
+      '#description' => t('The Globally unique identifier of the RSS item.'),

Globally should be lowercase

+++ b/plugins/views_plugin_row_rss_fields.incundefined
@@ -0,0 +1,174 @@
+    $item = new stdClass();
+    $item->title = $this->get_field($row_index, $this->options['title_field']);

This section could use some inline docs.

+++ b/plugins/views_plugin_row_rss_fields.incundefined
@@ -0,0 +1,174 @@
+      'attributes' => array('isPermaLink' => $guid_is_permalink_string)

Missing trailing comma

+++ b/plugins/views_plugin_row_rss_fields.incundefined
@@ -0,0 +1,174 @@
+   * Convinience method  to retrieve field output.

Double space, and the comment should start differently, like the docs say: "beginning with a verb in the form "Does such and such" (third person, as in "This function does such and such", rather than second person imperative "Do such and such")."

marvil07’s picture

Status: Needs work » Needs review
StatusFileSize
new3.04 KB
new8.82 KB

Thanks for the review

tim.plunkett’s picture

Status: Needs review » Needs work
+++ b/plugins/views_plugin_row_rss_fields.incundefined
@@ -0,0 +1,175 @@
+    $options['guid_field_options']['guid_field'] = array('default' => 'none', 'bool' => TRUE);
+    $options['guid_field_options']['guid_field_is_permalink'] = array('default' => TRUE);

Er, the bool is now on the wrong line. Sorry! I think this is good otherwise.

marvil07’s picture

Status: Needs work » Needs review
StatusFileSize
new8.82 KB
tim.plunkett’s picture

Status: Needs review » Needs work

Okay now I just feel like a jerk, but I thought of a couple more things.

+++ b/plugins/views_plugin_row_rss_fields.incundefined
@@ -0,0 +1,175 @@
+    $options['title_field'] = array('default' => 'none');
+    $options['link_field'] = array('default' => 'none');
+    $options['description_field'] = array('default' => 'none');
+    $options['creator_field'] = array('default' => 'none');
+    $options['date_field'] = array('default' => 'none');
+    $options['guid_field_options']['guid_field'] = array('default' => 'none');

See below about replacing 'none' with '';

+++ b/plugins/views_plugin_row_rss_fields.incundefined
@@ -0,0 +1,175 @@
+    foreach ($this->display->handler->get_handlers('field') as $field => $handler) {
+      $view_fields[$field] = $handler->ui_name();

Could this be replaced by $this->display->handler->get_field_labels();?

+++ b/plugins/views_plugin_row_rss_fields.incundefined
@@ -0,0 +1,175 @@
+      if (empty($this->options[$required_option]) || $this->options[$required_option] == 'none') {

If 'none' was replaced with '' as the empty default, these conditionals could be much simpler

+++ b/plugins/views_plugin_row_rss_fields.incundefined
@@ -0,0 +1,175 @@
+    if (empty($this->options['guid_field_options']['guid_field']) || $this->options['guid_field_options']['guid_field'] == 'none') {

.

marvil07’s picture

Status: Needs work » Needs review
StatusFileSize
new4.98 KB
new8.74 KB

I like those suggestions, thanks!

BTW: You was right get_field_label method do more than I was doing an it is necessary to use it.

tim.plunkett’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new3.07 KB
new8.91 KB

Okay, rerolled with a couple tweaks we discussed on IRC, I rolled it with credit for @marvil07 so this should be good to use with `git am`.

dawehner’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for all the work! I did a final review and committed it to 7.x-3.x

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.