get_default_args( self::ARG ); if ( is_string( $block ) && '' !== $block ) { return $block; } $type = $this->get_data( 'widgetType' ); return is_string( $type ) ? Factory::instance()->block_of( $type ) : ''; } /** * The block's markup for this widget's settings. */ public function rooster_markup(): string { return Factory::instance()->markup( $this->rooster_block(), (array) $this->get_settings_for_display() ); } /** * The block's name, "/" replaced by "-" ('aieo/toc' → 'aieo-toc'). * * @return string */ public function get_name() { return Factory::widget_name( $this->rooster_block() ); } /** * The block's title. * * @return string */ public function get_title() { return Factory::instance()->title( $this->rooster_block() ); } /** * The block's eicon. * * @return string */ public function get_icon() { return Factory::instance()->icon( $this->rooster_block() ); } /** * The product's category. * * @return list */ public function get_categories() { return array( Factory::instance()->category( $this->rooster_block() ) ); } /** * The product's keywords, then the block's. * * @return list */ public function get_keywords() { return Factory::instance()->keywords( $this->rooster_block() ); } /** * Offered in the panel only while its block type is registered. The widget itself stays registered, so a page * that holds it keeps its element. * * @return bool */ public function show_in_panel() { return Factory::registered( $this->rooster_block() ); } /** * The output follows the post, the visitor or the catalogue: Elementor must not cache the element's markup. */ protected function is_dynamic_content(): bool { return true; } /** * The block's wrapper is the widget's: no inner wrapper. */ public function has_widget_inner_wrapper(): bool { return false; } /** * The block's sheets (style and viewStyle; the token sheet when it reads the tokens), so a page that holds the * widget loads them in its head. * * @return list */ public function get_style_depends() { return Factory::instance()->styles( $this->rooster_block() ); } /** * The block's view scripts. * * @return list */ public function get_script_depends() { return Factory::instance()->scripts( $this->rooster_block() ); } /** * The block's controls in their sections (Content tab), the product's style controls (Style tab), then the * product's own controls. */ protected function register_controls() { $factory = Factory::instance(); $block = $this->rooster_block(); $id = $factory->id( $block ); $strings = $factory->strings( $block ); $options = static fn( array $control ): ?array => $factory->options( $block, $control ); Controls::add( $this, ControlMap::sections( $factory->controls( $block ), $factory->sections( $block ) ), $id, $options, $strings ); $style = $factory->arg( $block, 'style' ); $style = is_callable( $style ) ? (array) call_user_func( $style, $block ) : array(); if ( array() !== $style ) { Controls::style_section( $this, $id . '_style', $strings['style'], $style ); } $more = $factory->arg( $block, 'controls' ); if ( is_callable( $more ) ) { call_user_func( $more, $this, $block ); } } /** * Prints the block, escaped late: through \Rooster\Blocks\Kses::print() (wp_kses() with the package's list, filter * `rooster_blocks_allowed_html`; a style element's CSS through strip_tags(); an inline script through core's * inline-script API), or through the product's `print` when it gives one (it receives a callable that returns the * markup, and must escape too). */ protected function render() { $factory = Factory::instance(); $block = $this->rooster_block(); $settings = (array) $this->get_settings_for_display(); $markup = static fn(): string => $factory->markup( $block, $settings ); $print = $factory->arg( $block, 'print' ); if ( is_callable( $print ) ) { call_user_func( $print, $markup ); return; } \Rooster\Blocks\Kses::print( $markup() ); } }