Contribution plugin and tags

I see that the contribution plugin does not allow Tags to be added to the form. I dug around the plugin files a bit and cannot find the appropriate place to (attempt to) add that into the form. Where might I start?

Thanks -- Erin

First you can create your field input in views/public/contribution/contribribute.php

<div class="field">
            <label>Keywords (separated by comma):</label>
            <input type="text" class="textinput" name="tags" value="<?php echo html_escape($_POST['tags']) ?>" id="tags" />
        </div>

To assign your input to item tags you will need modify the $itemMetadata array found in the _processForm($post) function in the ContributionController.php file(controllers folder)

$itemMetadata = array('public'       => false,
                                  'featured'     => false,
                                  'item_type_id' => $itemTypeId,
				   'tags'=>$_POST['tags']);

Thanks Andrea!

FYI, for others, you may want to add a unique <legend> tag to the top of that code and place it within the existing <fieldset id="contribution-contributor-metadata"> around line 34, right above the Personal Information legend and fields.

<!-- tag hack ********************** -->
<legend>Tags</legend>
<div class="field">
<label>Keywords (separated by comma):</label>
<input type="text" class="textinput" name="tags" value="<?php echo html_escape($_POST['tags']) ?>" id="tags" />
</div>
<!-- end hack **********************-->

This will maintain the jQuery hide-show effect for the form and will keep your Tag entry field from appearing inside the wrong area.

Thanks again, Andrea.

If I can find the time, I may try to write up a quick plugin to add this to the Contribution form for people not comfortable editing code (and also so I don't have to redo this after the next update). I assume since the GeoLocation plugin can attach itself to the form, other plugins may do so, yes?

ebellempire:

You're right that other plugins can add stuff to the Contribution form. There's a plugin hook in Contribution called contribution_append_to_type_form, and a hook called contribution_save_form to actually save teh data posted through the form. Geolocation uses it, so you could take a look in there to see more about using it.

getting this error with the code above...

Cannot add tags to an item if no Entity is available to tag

This seems to work...

<!-- tag hack ********************** -->
		<legend>Tags</legend>
        <div class="field">
            <label>Keywords (separated by comma):</label>
				<div class="inputs">
                    <div class="input">
                        <?php echo $this->formText('tags', $_POST['tags'], array('class' => 'textinput')); ?>
                    </div>
                </div>
        </div>
        <!-- end hack **********************-->

The error came back again. I haven't pinned down what causes the error to happen only sometimes. (I had to disable it to avoid issues on an active project). Any guesses on what might be missing?