XF 2.1 What’s new for developers in XF 2.1?

Brad Padgett

Well-known member
Will there be an easy way to upgrade Font Awesome 4 icons to Font Awesome 5 without having to manually go in and change everything?

Possibly some code you could add into XF 2.1? Or is this process automatic?

I know there should be an easy way for the icons to get upgraded to their FA 5 state but wanted clarification.
 

Chris D

XenForo developer
Staff member
We already have a compatibility layer for some use cases, but that’s mostly in Less templates where the FA variables are used.

But, otherwise, no. You would need to update things manually.
 

Brad Padgett

Well-known member
We already have a compatibility layer for some use cases, but that’s mostly in Less templates where the FA variables are used.

But, otherwise, no. You would need to update things manually.
Yeah that's going to be a pain. At least it's worth it with all the hard work you guys put in. I have so many icons on my site. I have tons for mobile, nav, sidebar, account visitor menu, footer icons, whats new, profile page... a lot.

On that font awesome website if I'm not mistaken there was a piece of code they said you could put in your templates that would upgrade it. This is not the same for XF 2.1? In other words if I tried to put this same bit of code in a certain template it woudn't work? Is it not possible to inject the upgrade code somewhere?
 

Chris D

XenForo developer
Staff member
I think you’re referring to the JS shim. That’s not recommended for long term use anyway and doesn’t provide the best results. At best it would help get you through until you can update the icons manually.

There aren’t actually all that many which need updating. It’s worth the one time effort.

Either way we’d recommend you updating them to use the new <xf:fa> tag. It handles things like the icon weight automatically for each style and in future if icon names change we might be able to add a layer of compatibility in there if people are using our built in template tags for icons.
 

Brad Padgett

Well-known member
Well it's definitely worth it in the end. And yes that's what I was referring to. I will keep in mind the new syntax when I restore the icons. It's probably the only time anyone will have to do this in a very long time so it's not too big of a deal so your right about a one time effort. I appreciate the info.

Excited for 2.1 to release for dev purposes as well. I want to install the new release on localhost to get to work but it takes forever in a day to upgrade on localhost so I don't want to install a release candidate until it's official because I'll be waiting like 45 minutes to an hour to upgrade that version.

Anyways sounds good to me.
 

Chris D

XenForo developer
Staff member
Well it's definitely worth it in the end. And yes that's what I was referring to. I will keep in mind the new syntax when I restore the icons. It's probably the only time anyone will have to do this in a very long time so it's not too big of a deal so your right about a one time effort. I appreciate the info.

Excited for 2.1 to release for dev purposes as well. I want to install the new release on localhost to get to work but it takes forever in a day to upgrade on localhost so I don't want to install a release candidate until it's official because I'll be waiting like 45 minutes to an hour to upgrade that version.

Anyways sounds good to me.
Actually something that might help you out does exist.

There's a template called setup_fa4_variables.less
Less:
@fa-var-trash-o: @fa-var-trash-alt;
It contains a massive list of stuff like this.

This particular line indicates that the icon previously known as fa-trash-o is now known as fa-trash-alt.

So at the very least if you find a particular icon no longer works, you can look it up against this list.
 

Brad Padgett

Well-known member
Actually something that might help you out does exist.

There's a template called setup_fa4_variables.less
Less:
@fa-var-trash-o: @fa-var-trash-alt;
It contains a massive list of stuff like this.

This particular line indicates that the icon previously known as fa-trash-o is now known as fa-trash-alt.

So at the very least if you find a particular icon no longer works, you can look it up against this list.
Appreciate the input. I will keep this in mind
 

usmanakram

New member
Migrating from "Likes" to "Reactions"

If you currently have an add-on which implements a "Like" content handler you may be wondering how you migrate to "Reactions" in XF 2.1 and what will happen to your existing likes.

We have ensured that your add-on will continue to function as normal after upgrading to XF 2.1. This means that your existing like handler code, your existing like templates, alert templates for likes, entities, controllers and everything will continue to appear and function as it does now without you needing to make any changes.

In fact, if you'd like to, your add-on can continue to use likes going forward. That said, it would be safe to assume that the like system is now deprecated and it may be slated for removal at some point in the future. So it would be strongly recommended to embrace and implement the new reactions functionality as soon as possible.

But, the good news is, we've made it very simple to migrate to reactions through a number of different helpers.


AbstractSetup::migrateTableToReactions($tableName, $likesColumn = 'likes', $likeUsersColumn = 'like_users')

You would call this for each of your content types and pass in the table name where the changes need to apply. This renames the existing likes column to reaction_score, the existing like_users column to reaction_users and adds a new column named reactions (which stores a tally of which reactions have been applied to the content and how many times).


AbstractSetup::renameLikeAlertOptionsToReactions($contentTypes, $oldAction = 'like')

You can pass in an array of content types (or a single content type) here and this renames any "alert opt outs" to the new name. You will need to update any phrases related to alert opt outs too.


AbstractSetup::renameLikeAlertsToReactions($contentTypes, $renameNewsFeed = true, $oldAction = 'like')

This renames any existing "like" alerts to a "reaction" alert with the required extra data, and if enabled also any news feed entries. In addition to this, you will need to update any like alert/news feed templates. Use a core template such as alert_post_reaction and news_feed_item_post_reaction for reference.


AbstractSetup::renameLikePermissionsToReactions(array $permissionGroupIds, $likePermissionId = 'like')

Given an array of permission group IDs, this will rename any existing permission with an ID of like (or a custom ID) to react. The array you pass in should actually have the existing permission group ID as its key, and a true or false value to denote whether or not it is a content specific permission or global only, similar to this:
PHP:
$this->renameLikePermissionsToReactions([
   'forum' => true, // global and content
   'conversation' => false, // global only
   'profile_post' => false // global only
]);

XF\Entity\ReactionTrait trait

After removing most references to likes in your content entity, you will need to add in some new reaction specific stuff. To make this easier, we've added a new ReactionTrait. This will require you to implement a canReact method (which will mostly be the same as your existing canLike method).


Templates and controller actions

Similar to the existing XF:Like controller plugin, there is a new XF:Reaction controller plugin. These will help you very easily start supporting the user interface for likes. In fact, there are no custom templates to create at all for interacting with reactions as the controller plugin will call default templates for this purpose. You can check out XF\Pub\Controller\Post for examples.

The only thing you would need to change in your templates is the existing like link and like summary code. Even for these, we've got some new XF template tags to help. Check out the post_macros template for an example.
Hye! i am beginer and its my first question. please guide me:
I am using this reactiontrait method in my addon. i have changed the actionReact as per my requirement:

public function actionReact(ParameterBag $params)
{
$entry = $this->assertViewableEntry($params->entry_id);

/** @var \XF\ControllerPlugin\Reaction $reactionPlugin */
$reactionPlugin = $this->plugin('XF:Reaction');
return $reactionPlugin->actionReactSimple($entry, 'flp-entries');
}


and in entity:

public function canReact(&$error = null)
{
$visitor = \XF::visitor();
if (!$visitor->user_id) {
return false;
}
if ($this->message_state != 'visible')
{
return false;
}

if ($visitor->is_admin) {
return true;
}

if ($this->user_id == $visitor->user_id)
{
$error = \XF::phraseDeferred('reacting_to_your_own_content_is_considered_cheating');
return false;
}

return $visitor->hasPermission('flp_blogs' ,'canLikeBlogEntries');
}


and from post_macros and i copied the syntax and changed to:
<xf:react content="{$entry}" link="flp-entries/react" list="< .js-post | .js-reactionsList" />

and i got the error:
An exception occurred: [Error] Call to undefined method Flp\Blog\Entity\Blog_Entry::getReactionContent() in src/XF/Template/Templater.php on line 3080
  1. XF\Template\Templater->fnReact()
  2. call_user_func_array() in src/XF/Template/Templater.php at line 922
  3. XF\Template\Templater->fn() in internal_data/code_cache/templates/l1/s1/public/flp_blog_entry_view.php at line 268
  4. XF\Template\Templater->{closure}() in src/XF/Template/Templater.php at line 1301
  5. XF\Template\Templater->renderTemplate() in src/XF/Template/Template.php at line 24
  6. XF\Template\Template->render() in src/XF/Mvc/Renderer/Html.php at line 48
  7. XF\Mvc\Renderer\Html->renderView() in src/XF/Mvc/Dispatcher.php at line 418
  8. XF\Mvc\Dispatcher->renderView() in src/XF/Mvc/Dispatcher.php at line 400
  9. XF\Mvc\Dispatcher->renderReply() in src/XF/Mvc/Dispatcher.php at line 360
  10. XF\Mvc\Dispatcher->render() in src/XF/Mvc/Dispatcher.php at line 53
  11. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2177
  12. XF\App->run() in src/XF.php at line 390
  13. XF::runApp() in index.php at line 20
thanks in Advance.
 

usmanakram

New member
Hye! i am beginer and its my first question. please guide me:
I am using this reactiontrait method in my addon. i have changed the actionReact as per my requirement:

public function actionReact(ParameterBag $params)
{
$entry = $this->assertViewableEntry($params->entry_id);

/** @var \XF\ControllerPlugin\Reaction $reactionPlugin */
$reactionPlugin = $this->plugin('XF:Reaction');
return $reactionPlugin->actionReactSimple($entry, 'flp-entries');
}


and in entity:

public function canReact(&$error = null)
{
$visitor = \XF::visitor();
if (!$visitor->user_id) {
return false;
}
if ($this->message_state != 'visible')
{
return false;
}

if ($visitor->is_admin) {
return true;
}

if ($this->user_id == $visitor->user_id)
{
$error = \XF::phraseDeferred('reacting_to_your_own_content_is_considered_cheating');
return false;
}

return $visitor->hasPermission('flp_blogs' ,'canLikeBlogEntries');
}


and from post_macros and i copied the syntax and changed to:
<xf:react content="{$entry}" link="flp-entries/react" list="< .js-post | .js-reactionsList" />

and i got the error:
An exception occurred: [Error] Call to undefined method Flp\Blog\Entity\Blog_Entry::getReactionContent() in src/XF/Template/Templater.php on line 3080
  1. XF\Template\Templater->fnReact()
  2. call_user_func_array() in src/XF/Template/Templater.php at line 922
  3. XF\Template\Templater->fn() in internal_data/code_cache/templates/l1/s1/public/flp_blog_entry_view.php at line 268
  4. XF\Template\Templater->{closure}() in src/XF/Template/Templater.php at line 1301
  5. XF\Template\Templater->renderTemplate() in src/XF/Template/Template.php at line 24
  6. XF\Template\Template->render() in src/XF/Mvc/Renderer/Html.php at line 48
  7. XF\Mvc\Renderer\Html->renderView() in src/XF/Mvc/Dispatcher.php at line 418
  8. XF\Mvc\Dispatcher->renderView() in src/XF/Mvc/Dispatcher.php at line 400
  9. XF\Mvc\Dispatcher->renderReply() in src/XF/Mvc/Dispatcher.php at line 360
  10. XF\Mvc\Dispatcher->render() in src/XF/Mvc/Dispatcher.php at line 53
  11. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 2177
  12. XF\App->run() in src/XF.php at line 390
  13. XF::runApp() in index.php at line 20
thanks in Advance.
i think the problem is on content="{$entry}" in template
 

Chris D

XenForo developer
Staff member
We can only provide support to licensed customers and in the designated areas.

You may need to associate your forum username with your license.
 
Top