This thread is over two years old and may be outdated. Please create a new thread if you need help, or email us if you have an active Premium license.

How can I Control the Widget description in a PageBuilder grid

10 years ago · Last reply by LuBevilacqua 9 years ago

Hi!
I’m developing a SO widget which offers several different options and “look”, set via a `select`form field type.
As you can see, using 3 instances of the same widget could quickly become confusing.

How can I display each widget’s current option state in the Page Builder Editor ? I’ve discovered that the ‘panels_title’ key set to false at least hides the query vars url, which is good. Can it perhaps display current instance’s option values?

class Vignette_Widget extends SiteOrigin_Widget {
	function __construct() {
		//Here you can do any preparation required before calling the parent constructor, such as including additional files or initializing variables.
		//Call the parent constructor with the required arguments.
		parent::__construct(
			// The unique id for your widget.
			'vignette-widget',
			// The name of the widget for display purposes.
			'Vignette Widget',
			// The $widget_options array, which is passed through to WP_Widget.
			// It has a couple of extras like the optional help URL, which should link to your sites help or support page.
			array(
				'description' => 'Une "vignette" d'un article et son affichage.',
				'panels_groups' => array('customer'),
				'panels_icon' => 'dashicons dashicons-analytics',
				'panels_title' => false,
//				'help'        => 'http://example.com/hello-world-widget-docs',
			),

Thanks!!!

This is our free support forum. Replies can take several days.

Need fast email support? Get SiteOrigin Premium

Replies

1
  1. LuBevilacqua 9 years, 9 months ago

    Hello,
    I know this is an old thread but I encountered the same problem and I would like to share a viable solution.
    The description of the widget is written by the main js “siteorigin-panels-xx.js”, specifically through a (misnamed?) function getTitle, line 2835 as of version 24.
    In the line 2842 you can find

    else if ( ! _.isUndefined( widgetData.panels_title ) ) {
        // This means that the widget has told us which field it wants us to use as a title
        if ( widgetData.panels_title === false ) {
            return panelsOptions.widgets[this.get( 'class' )].description;
        }
    }

    Here seems like developers put the basis for panels_title usage, but considering it only if set to false.
    I would suggest to use panels_title as a reference to the field that we want to display as description of the widget:

    else if ( ! _.isUndefined( widgetData.panels_title ) ) {
        // This means that the widget has told us which field it wants us to use as a title
        if ( widgetData.panels_title === false ) {
            return panelsOptions.widgets[this.get( 'class' )].description;
        } else {
            // Get every value and iterate the keys
            var values = this.get('values');
            for (var k in values) {
                if(typeof values[k] !== 'object'){
                    if (values.hasOwnProperty(k) && k == widgetData.panels_title) {
                        return values[k];
                    }
                } else {
                    // If we are into a section, check inside keys too            
                    for(var j in values[k]){
                        if(values[k].hasOwnProperty(j) && j == widgetData.panels_title) {
                            return values[k][j];
                        }
                    }
                }
            }
        }
    }

    Of course this is just a temporary solution, but I would like to suggest this feature to the official developers, it can be very helpful when you need a lot of widgets on the same page.
    Hope it helps!
    Have a nice day
    Luigi

Replies on this thread are closed.

Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Have a different question or issue?

Start New Thread