How do I override engine code?

I added a small if statement to a function in /engine/lib/entities.php

How can I add that change to a plugin? Is it possible to just copy that core file to myplugin/engine/lib/entities.php and make the change there?

  • No, you can't just copy it into a plugin, it doesn't work like views.


    What is it you're trying to achieve?

  • Share your requirements. most things can be done with plugin / event hooks.

  • those 2 points above are valid..
    if need good assistance - answer both questions

    generally - functionalities should be achiveable with hooks etc
    and only in the very rare cases might a core code change be needed

    you should be available soon enough to supply a requirements statement 
    and that 1 line of 'if' code + 10 lines before + 10 lines after
    to enable quicker understanding of your purpose
    and then we can fiigure the better/best way through

     

  • Yeah sure. In /engine/lib/entities.php, I added a small if statement to the elgg_list_entities() function:

    function elgg_list_entities(array $options = array(), $getter = 'elgg_get_entities',
    	$viewer = 'elgg_view_entity_list') {
    
    	global $autofeed;
    	$autofeed = true;
    
    	$defaults = array(
    		'offset' => (int) max(get_input('offset', 0), 0),
    		'limit' => (int) max(get_input('limit', 10), 0),
    		'full_view' => TRUE,
    		'list_type_toggle' => FALSE,
    		'pagination' => TRUE,
    	);
    
    	//the "small if statement"
    	if(isset($options['pagination']) && $options['pagination'] == FALSE){
    		$options['offset'] = 0;
    	}
    	//end the "small if statement"
    
    	$options = array_merge($defaults, $options);
    
    	//backwards compatibility
    	if (isset($options['view_type_toggle'])) {
    		$options['list_type_toggle'] = $options['view_type_toggle'];
    	}
    
    	$options['count'] = TRUE;
    	$count = $getter($options);
    
    	$options['count'] = FALSE;
    	$entities = $getter($options);
    
    	$options['count'] = $count;
    
    	return $viewer($entities, $options);
    }
    

    I am using the Custom Index Widgets mod to have the latest activity and the latest wire posts widgets show up on the index page. I want the activity widget to be paginated which is fine and works, but when you have ?offset=10 in the url, the latest wire posts get offset as well. However in the latest wire posts widget, pagination is set to false.

    This is not an issue only with latest wire posts, but latest files and a bunch of other widgets that set pagination to false but don't set offset to 0 when they call elgg_list_entities()... I am also using Widget Manager and it's also a problem with profile and group pages which have widgets that have pagination enabled and widgets that don't.

    I could simply edit each widget that has pagination set to false and just set offset to 0.. but it's much easier to just add this if statement to the engine..

    I don't like to edit core but otherwise I would be modifying like 15-20 files in the mod folder..

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking