Minor changes to vendor files

I need to introduce a minor change to the messages in each of the following files:

path/vendor/elgg/elgg/js/lib/elgglib.js
 
path/vendor/elgg/elgg/views/default/page/elements/messages.php
Should I overwrite these pages in my plugin or there is a better way?
Thanks for your guidance.
  • Not knowing what you want to change I would say if overridding works for you just do it this way.

  • I want to add a "close" text to the system messages, e.g. <p style="text-align: right; color: #e8f907;">close</p>.

    ​Below you'll see my added code to messages.php and elgglib.js. It works well when I change the core (temporarily of course). I've not yet overridden it with a plugin but I believe it will work. However, I think that since the system messages are triggered by events, it should be possible to add the code through a plugin hook, but I do not know how to do it.

    Thank you very much.

    --------------------------------------------- 

    In messages.php the code is:

    please note my added code in the comment "my addition". 

    echo '<ul class="elgg-system-messages">';
    
    
    // hidden li so we validate
    
    echo '<li class="hidden"></li>';
    
    
    if (isset($vars['object']) && is_array($vars['object']) && sizeof($vars['object']) > 0) {
    
    foreach ($vars['object'] as $type => $list ) {
    
    foreach ($list as $message) {
    
    echo "<li class=\"elgg-message elgg-state-$type\">";
    
    echo elgg_autop($message);
    
    echo '<p style="text-align: right; color: #e8f907;">close</p>';//==== my addition
    
    echo '</li>';
    
    }
    
    }
    
    }
    
    
    echo '</ul>';

    And in elgglib.js, the code is:

    please note my added code in the comment "my addition". 

    elgg.system_messages = function(msgs, delay, type) {
    
    if (elgg.isUndefined(msgs)) {
    
    return;
    
    }
    
    
    var classes = ['elgg-message'],
    
    messages_html = [],
    
    appendMessage = function(msg) {
    
    messages_html.push('<li class="' + classes.join(' ') + '"><p>' + msg + 
    '</p><p style="text-align: right; color: #e8f907;">close</p></li>');//=== my addition
    
    },
    
    systemMessages = $('ul.elgg-system-messages'),
    
    i;
    
    .... etc....

     

     

     

     

  • Just override this view:

    views/default/page/elements/messages.php

    as

    /mod/your_plugin/views/default/page/elements/messages.php

    And this:

    views/default/elgg.js.php

    as

    /mod/your_plugin/views/default/elgg.js.php

    Where add location of your rewritted elgglib.js instead of

    $elggDir->getPath("js/lib/elgglib.js"),
  • Works great.

    views/default/elgg.js.php is new to me... good to know :)

    Thank you very much RvR