Custom Field On Click Add Tag But No select link

@twisted1919

You are correct. It shows as custom action as 1 . But the link is not prepopulated when edit is clicked http://screencast.com/t/QjAt452xxmf

Also, I want to know is it possible to "add" a value to an existing tag instead of complete update?
I am a developer, if you guide me I can create custom code to create this myself and share with community
 
Last edited:
@developer - Ah, i see, so the link is not selected in edit mode, but still, it is part of the dropdown options, right?
Related to adding a value, that's a bit difficult, but doable. if you look at /apps/frontend/controllers/CampaignsController.php Line 194 you will see how we add an action for the 'frontend_campaigns_after_track_url_before_redirect' hook:
Code:
Yii::app()->hooks->addAction('frontend_campaigns_after_track_url_before_redirect', array($this, '_urlActionChangeSubscriberListField'), 99);
From an extension you can remove this action:
Code:
Yii::app()->hooks->removeAction('frontend_campaigns_after_track_url_before_redirect', array($this, '_urlActionChangeSubscriberListField'));
And then you can attach your own action:
Code:
Yii::app()->hooks->addAction('frontend_campaigns_after_track_url_before_redirect', function(Controller $controller, Campaign $campaign, ListSubscriber $subscriber, CampaignUrl $url){
    $models = CampaignTemplateUrlActionListField::model()->findAllByAttributes(array(
        'campaign_id' => $campaign->campaign_id,
        'url'         => $url->destination,
    ));
    if (empty($models)) {
        return;
    }
    foreach ($models as $model) {
        $valueModel = ListFieldValue::model()->findByAttributes(array(
            'field_id'      => $model->field_id,
            'subscriber_id' => $subscriber->subscriber_id,
        ));
        if (empty($valueModel)) {
            $valueModel = new ListFieldValue();
            $valueModel->field_id       = $model->field_id;
            $valueModel->subscriber_id  = $subscriber->subscriber_id;
        }
        // append the value instead.
        $valueModel->value .= $model->field_value;
        $valueModel->save();
    }
}, 99);

And that's all there is to it.
 
@twisted1919 Thanks a ton!

The solution works like charm

One issue though

Since now we are appending instead of replacing, on multiple clicks the same tags are being added repetitively http://screencast.com/t/pGxDEsCdP

I tried to to use the substring function to check for duplicates but not good at YII framework all greek and latin

Can you guide me which fields should I check for duplicate tags?
 
@developer - sure, here's how you do it:
PHP:
$valueModel->value .= $model->field_value;
// and now the change.
$valueModel->value  = explode(',', $valueModel->value);
// this will make sure we only keep unique tags and remove empty strings if any
$valueModel->value  = implode(', ', array_filter(array_unique(array_map('trim', $valueModel->value))));
 
@twisted1919 Tx! Works like charm

Here is the completed if anyone is interested

PHP:
Yii::app()->hooks->removeAction('frontend_campaigns_after_track_url_before_redirect', array($this, '_urlActionChangeSubscriberListField'));
        Yii::app()->hooks->addAction('frontend_campaigns_after_track_url_before_redirect', function(Controller $controller, Campaign $campaign, ListSubscriber $subscriber, CampaignUrl $url){
    $models = CampaignTemplateUrlActionListField::model()->findAllByAttributes(array(
        'campaign_id' => $campaign->campaign_id,
        'url'         => $url->destination,
    ));
    if (empty($models)) {
        return;
    }
    foreach ($models as $model) {
        $valueModel = ListFieldValue::model()->findByAttributes(array(
            'field_id'      => $model->field_id,
            'subscriber_id' => $subscriber->subscriber_id,
        ));
        if (empty($valueModel)) {
            $valueModel = new ListFieldValue();
            $valueModel->field_id       = $model->field_id;
            $valueModel->subscriber_id  = $subscriber->subscriber_id;
        }
        // append the value instead.
        $valueModel->value .= $model->field_value;
         $valueModel->value  = explode(',', $valueModel->value);
    // this will make sure we only keep unique tags and remove empty strings if any
    $valueModel->value  = implode(', ', array_filter(array_unique(array_map('trim', $valueModel->value))));
        $valueModel->save();
    }
}, 99);"

Steps to make changes

Step:-1 Got To public_html/apps/frontend/controllers
Step:-2 Edit CampaignsController.php
Step:-3 Comment For this Line check Screen shot :- http://screencast.com/t/WGsnPLWRtkC

Step:-4 Next Line Copy for code.
Step:-5 Add Code Above
Step:-6 Ensure that the tags start with a comma "," so instead of book,potter use ,book,potter, for the code to work correctly
 
Last edited:
@twisted1919 Tx! Works like charm

Here is the completed if anyone is interested

PHP:
"Yii::app()->hooks->removeAction('frontend_campaigns_after_track_url_before_redirect', array($this, '_urlActionChangeSubscriberListField'));
        Yii::app()->hooks->addAction('frontend_campaigns_after_track_url_before_redirect', function(Controller $controller, Campaign $campaign, ListSubscriber $subscriber, CampaignUrl $url){
    $models = CampaignTemplateUrlActionListField::model()->findAllByAttributes(array(
        'campaign_id' => $campaign->campaign_id,
        'url'         => $url->destination,
    ));
    if (empty($models)) {
        return;
    }
    foreach ($models as $model) {
        $valueModel = ListFieldValue::model()->findByAttributes(array(
            'field_id'      => $model->field_id,
            'subscriber_id' => $subscriber->subscriber_id,
        ));
        if (empty($valueModel)) {
            $valueModel = new ListFieldValue();
            $valueModel->field_id       = $model->field_id;
            $valueModel->subscriber_id  = $subscriber->subscriber_id;
        }
        // append the value instead.
        $valueModel->value .= $model->field_value;
         $valueModel->value  = explode(',', $valueModel->value);
    // this will make sure we only keep unique tags and remove empty strings if any
    $valueModel->value  = implode(', ', array_filter(array_unique(array_map('trim', $valueModel->value))));
        $valueModel->save();
    }
}, 99);"

So how should we call this and where exactly should it be patched-in?
 
@frm.mwz - that is just a special use case where he created an extension from which he hooked into mailwizz hooks to alter the original behavior of the app.
 
Back
Top