# elementor/4.2.0-beta1/modules/global-classes/concerns/has-preview-context.php

Elementor Website Builder – more than just a page builder, version 4.2.0-beta1. 48 lines.

- Page: https://pluginprobe.com/plugins/elementor/4.2.0-beta1/code/modules/global-classes/concerns/has-preview-context.php
- Raw: https://pluginprobe.com/plugins/elementor/4.2.0-beta1/raw/modules/global-classes/concerns/has-preview-context.php
- Modified: 2026-05-20T12:19:28+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/elementor/4.2.0-beta1/code/modules/global-classes/concerns/has-preview-context.php#L10-L20`.

```php
<?php

namespace Elementor\Modules\GlobalClasses\Concerns;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

trait Has_Preview_Context {
	private bool $is_preview = false;

	public function set_preview( bool $is_preview = true ): self {
		if ( $is_preview === $this->is_preview ) {
			return $this;
		}

		$this->is_preview = $is_preview;
		$this->on_preview_change();

		return $this;
	}

	protected function is_preview(): bool {
		return $this->is_preview;
	}

	protected function get_context_key( string $key ): string {
		$map = $this->get_context_keys()[ $key ] ?? null;

		if ( null === $map ) {
			throw new \InvalidArgumentException( sprintf( 'Unknown context key: %s', esc_html( $key ) ) );
		}

		return $this->is_preview ? $map['preview'] : $map['frontend'];
	}

	protected function get_context_keys(): array {
		if ( empty( $this->context_keys ) ) {
			return [];
		}

		return $this->context_keys;
	}

	protected function on_preview_change(): void {
	}
}

```
