1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Creating a new LikeHandler

Discussion in 'XenForo Development Discussions' started by HDJuegos, Oct 28, 2010.

  1. HDJuegos

    HDJuegos Active Member

    Hi, i'm creating a new LikeHandler to allow my users to "Like" more things than Posts and ProfilePosts. Objective: A likehandler for a new content in my forum (like videos in video-directory):

    To do it, i create a new content_type:

    Data in xf_content_type (content_type,addon_id,fields)

    'myContentType', 'MyAddon', 'a:1:{s:18:"like_handler_class";s:30:"MyAddon_LikeHandler_MyContent";}'
    Data in xf_content_type_fields:

     'myContentType', 'like_handler_class', 'MyAddon_LikeHandler_MyContent'
    I do the new likehandler class and put it in LikeHandler folder but i have a problem in my controllerpublic with the next code in actionLike function:

    $latestUsers = $likeModel->likeContent('myContentType', $mycontentid, $contentuserid);
    This code returns false and don't create a new like because the next code in Model -> Like.php returns false:

    $likeHandler = $this->getLikeHandler($contentType)
    So XenForo don't find the new content_type, althought all fields are filled in DataBase.

    I'm doing something wrong?. Thanks in advance
  2. Arik

    Arik Well-Known Member

    Did you clear the content type cache (in the xf_data_registry table)?

    If not, make sure you call XenForo_Model_ContentType::rebuildContentTypeCache

    I haven't build any new content types, but that REALLY threw me for a loop when I created a new Node Type.
    HDJuegos likes this.
  3. HDJuegos

    HDJuegos Active Member

    When i need to call rebuildContentTypeCache? From ControllerPublic Class?
  4. Dismounted

    Dismounted Well-Known Member

    Have a look at my add-on called Report Conversations. It adds a new report handler, and you can adapt that to suit the likes handler.
    Fuhrmann and HDJuegos like this.
  5. HDJuegos

    HDJuegos Active Member

    Great !. Function works, now my contentType can be "liked" by users. A lot of thanks , Dismounted and Arik
  6. Jaxel

    Jaxel Well-Known Member

    Hey HDJuegos... I am trying to add a likeHandler to my Media Library mod... Do you mind jotting down EXACTLY everything you did to create a custom like handler?
    anotheralias likes this.
  7. Dismounted

    Dismounted Well-Known Member

    If you look inside xf_content_type_field you'll be able to see the callback class that is specified for a specific content type. You need to do the same - and you can base that off my own modification if you like. You just need to use the default like handlers' code for your purposes (instead of a report handler).
  8. Jaxel

    Jaxel Well-Known Member

    The handlers confuse me... there is just way too much going on... and I don't understand "blobs" yet...

    Basically I just want the following handlers...

    Media Library
    • news feed for when someone submits a media
    • news feed for when someone comments on a media
    • news feed for when someone likes a media
    • like handler for who has liked a media
    • report handler so people can report media
    • moderation queue handler for new media
    • moderation queue handler for comments
    • news feed for when someone creates a new article
    • news feed for when someone edits an article
    • news feed for when someone comments on an article
    • report handler so people can report vandalism
    • moderation queue handler for new articles
  9. HDJuegos

    HDJuegos Active Member

    Sorry Jaxel, i will post how to do a LikeHandler tomorrow.

    Basically i created it into Database, and extends the handler controller. You need to rebuild the content type cache to allow the Like.php call
    $likeHandler = $this->getLikeHandler($contentType)

    This will posts into the news feed table your "liked" content.
  10. cedivad

    cedivad Active Member

    I'm waiting for it, if you have time!

Share This Page