Support » Plugin: Elementor Website Builder » Add custom structure preset in section

  • Resolved Mukesh Panchal

    (@mukesh27)


    Hello,

    How we can add a custom structure preset in the section?

    For example: In a section, we have to use three-column with width( 25 + 50 + 25 ) column width does not allow us to make it 100% width so we have to add a custom preset for that width.

    We tried to override the default section class but it will not work and show the below error

    Fatal error: Uncaught Error: Argument 1 passed to Elementor\Controls_Stack::sanitize_settings() must be of the type array, null given, called in /var/www/html/wordpress/wp-content/plugins/elementor/includes/base/controls-stack.php on line 1012
    in /var/www/html/wordpress/wp-content/plugins/elementor/includes/base/controls-stack.php on line 2038

    Code:

    class Section_Extend extends Element_Section {
    
    	private static $presets = [];
    
    	public function __construct() {
              $this->get_initial_config();
            }
    
            protected function get_initial_config() {
    		$config = parent::get_initial_config();
    
    		$config['presets'] = self::get_presets();
    		$config['controls'] = parent::get_controls();
    		$config['tabs_controls'] = parent::get_tabs_controls();
    
    		return $config;
    	}
    
            public static function get_presets( $columns_count = null, $preset_index = null ) {
    		if ( ! self::$presets ) {
    			self::init_presets();
    		}
    
    		$presets = self::$presets;
    
    		if ( null !== $columns_count ) {
    			$presets = $presets[ $columns_count ];
    		}
    
    		if ( null !== $preset_index ) {
    			$presets = $presets[ $preset_index ];
    		}
    
    		return $presets;
    	}
    
    	public static function init_presets() {
    		$additional_presets = [
    			3 => [
    				[
    					'preset' => [ 25, 25, 50 ],
    				],
    				[
    					'preset' => [ 50, 25, 25 ],
    				],
    				[
    					'preset' => [ 25, 50, 25 ],
    				],
    			],
    		];
    
    		foreach ( range( 1, 10 ) as $columns_count ) {
    			self::$presets[ $columns_count ] = [
    				[
    					'preset' => [],
    				],
    			];
    			$preset_unit = floor( 1 / $columns_count * 100 );
    
    			for ( $i = 0; $i < $columns_count; $i++ ) {
    				self::$presets[ $columns_count ][0]['preset'][] = $preset_unit;
    			}
    
    			if ( ! empty( $additional_presets[ $columns_count ] ) ) {
    				self::$presets[ $columns_count ] = array_merge( self::$presets[ $columns_count ], $additional_presets[ $columns_count ] );
    			}
    
    			foreach ( self::$presets[ $columns_count ] as $preset_index => & $preset ) {
    				$preset['key'] = $columns_count . $preset_index;
    			}
    			
    		}
    	}
    }
Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for your patience.

    We apologize for the delay.
    In case it still relevant, please submit a ticket by sending an email to “support@elementor.com”

    Best Regards,
    Said

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.