New Landing How can we help? Cardinal Sort Saved elements in page builder by name ASC/DESC

Viewing 9 posts - 1 through 9 (of 9 total)
  • Posted in: Cardinal
  • #126467
    gircat
    Member
    Post count: 16

    Hello,

    I am trying to sort the saved elements in the page builder. I’m quite sure this must be done in the file “layouts” (cardinal/swift-framework/page-builder/inc). Most probably in line 165:

    class SPBElementsMenu implements SPBTemplateInterface {
    protected $params = Array();

    public function setup( $params ) {
    $this->params = (array) $params;

    return $this;
    }

    public function output( $post = null ) {
    if ( empty( $this->params ) ) {
    return ”;
    }
    $output = ‘<li class=”nav-header”>’ . __( ‘Load Element’, ‘swift-framework-admin’ ) . ‘‘;
    $is_empty = true;
    foreach ( $this->params as $id => $element ) {
    if ( is_array( $element ) ) {
    $element_button = new SPBSavedElementsMenuButton();
    $output .= $element_button->setup( $element )->setID( $id )->output();
    $is_empty = false;
    }
    }
    if ( $is_empty ) {
    $output .= ‘<li class=”spb_no_elements”><span>’ . __( ‘You have not saved any elements yet.’, ‘swift-framework-admin’ ) . ‘</span>‘;
    }

    return $output;
    }
    }

    But somehow I can’t manage to sort the array as the usual wordpress manner:
    ( array ( ‘orderby’ => ‘title’, ‘order’ => ‘DESC’ ) );

    Also, if possible, I would like to know how to group the items by some Html tags as titles, hr, etc.

    Thanks a lot,
    Ricard

    #126567
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    You should look in the class SPBElements_r and adapt the function getElementsList() to modify the array of elements and return it with your desired order.

    The loop is build in cardinal\swift-framework\page-builder\inc\layouts.php around line 332

    -Rui

    #126637
    gircat
    Member
    Post count: 16

    Hello,

    Thanks for your hint. I’ve been trying many things without success. Please can you show me the way to sort it by noame/title? So far I’ve been trying things like these, trying with “name” or “title” for the “orderby”:

    Your help will be much appreciated.
    Cheers,
    R.

    
     class SPBElements_r extends SFPageBuilderAbstract {
    
            protected $elements = Array( 'orderby' => 'name', 'order' => 'DESC' );
    
            public function getMenu() {
                $elements_menu = new SPBElementsMenu();
    
                return $elements_menu->setup( $this->getElementsList() )->output();
            }
    
            protected function getElements() {
                if ( $this->elements == null ) {
                    $this->elements = (array) get_option( 'spb_elements' );
                }
    
                return $this->elements;
            }
    
            public function getElementsList() {
                $this->elements = (array) $elements;
    
                return $this;
    
            }
        }
        
    //////////////
            
    public function getTemplatesList() {
     	$this->elements = (array( 'orderby' => 'name', 'order' => 'DESC' ));
        return $this->getTemplates();
    }
    
     
    //////////////
    
    public function getElementsList() {
    	$resultat = array('orderby' => 'name', 'order' => 'DESC'); 
        $this->elements = (array) $resultat;
    
        return $this->getElements();
    
    }   
            
    //////////////
           
    public function getElementsList() {
        $this->getElements(array( 'orderby' => 'title', 'order' => 'DESC' ));
        return $this->elements;
    }   
    
            
    //////////////
     public function getElementsList() {
      	asort($elements);
    	foreach ($elements as $key => $val) {
        echo "$val";
    }  
    
    #126869
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Hi

    I’ve forwarded this to Rui, he will assist you shortly ๐Ÿ™‚

    – Kyle

    #127286
    gircat
    Member
    Post count: 16

    Thanks,

    I’ll be looking forward.

    Cheers.

    #127376
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Hi,

    The idea was to show you the way. This is an example of an array with 2 itens.
    https://www.dropbox.com/s/6dcrduu6sf2dahq/elemens_array.png?dl=0

    This is a customization that could be complicated and take sometime so that’s outside the scope of our support because we just don’t have enough time to do it.

    This is the specific place where the array should be manipulated:

    
     protected function getElements() {
                if ( $this->elements == null ) {
                    $this->elements = (array) get_option( 'spb_elements' );
                }
    			
    		//here manipulate $this->elements	
    
                return $this->elements;
            }

    -Rui

    #130830
    gircat
    Member
    Post count: 16

    Hi Rui,

    Finally we managed to do it with this:

     protected function getElements() {
                if ( $this->elements == null ) {
                    $this->elements = (array) get_option( 'spb_elements' );
                }
                
    // Just with a sort
              sort($this->elements);	
    
                return $this->elements;
            }

    An then the HTML I will do it with CSS content after and berfore.

    !!

    #130844
    Kyle – SUPPORT
    Moderator
    Post count: 35880

    Ok great ๐Ÿ™‚

    – Kyle

    #130847
    Rui Guerreiro – SUPPORT
    Keymaster
    Post count: 25779

    Great. Glad your sorted it.
    -Rui

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in and have valid license to reply to this topic.

License required for one of the following items
Login and Registration Log in · Register