Read more * @button_label Add Mount Point * @a-no-tab 1 * @a-order 2 */ public array $mount_points; // just define without any annotations, it'll be overwritten by children. public string $template_engine; public bool $is_markup_with_digital_id; public string $custom_markup; public string $markup; public string $css_code; public string $js_code; public string $web_component; public string $classes_generation; public string $bem_name; public string $css_classes; /** * @a-deprecated This argument is used just to hide the field from the UI * @a-type textarea */ public string $sass_code; // declare type as 'textarea', otherwise new line characters will be removed. /** * @a-deprecated This argument is used just to hide the field from the UI * @a-type textarea */ public string $ts_code; // declare type as 'textarea', otherwise new line characters will be removed. /** * @a-deprecated This argument is used just to hide the field from the UI */ public string $unique_id; /** * This field is used in the Git feature, so old items can be updated while importing * * @a-deprecated This argument is used just to hide the field from the UI */ public string $plugin_version; /** * @a-deprecated This argument is used just to hide the field from the UI */ public bool $is_without_web_component; /** * @return string[] */ abstract protected function get_used_meta_group_ids(): array; abstract public function get_css_code( string $mode ): string; abstract public function has_unique_bem_name(): bool; /** * @return array */ abstract public function get_multilingual_strings(): array; abstract public function get_bem_name(): string; protected function resolved_css_code( string $css_code, string $mode, string $alias ): string { if ( self::CODE_MODE_DISPLAY === $mode ) { $markup_id = $this->get_markup_id(); $selector = $this->is_with_shadow_dom() ? ':host' : // direct won't work here, as the top element is out of the shadow root. $this->resolve_css_selector( $markup_id ); // magic shortcuts. $css_code = str_replace( sprintf( '#%s__', $alias ), sprintf( '%s .%s__', $selector, $this->get_bem_name() ), $css_code ); $css_code = str_replace( sprintf( '#%s', $alias ), sprintf( '%s', $selector ), $css_code ); // covers #this__, #this--, and just #this { ... }. $css_code = str_replace( '#this', // do not use $selector here, as we never need ':host' here. sprintf( '.%s', $this->get_bem_name() ), $css_code ); // for back compatibility. $css_code = str_replace( '#__', // do not use $selector here, as we never need ':host' here. sprintf( '.%s__', $this->get_bem_name() ), $css_code ); $css_code = trim( $css_code ); } elseif ( self::CODE_MODE_PREVIEW === $mode ) { $css_code = str_replace( sprintf( '#%s__', $alias ), sprintf( '#%s .%s__', $alias, $this->get_bem_name() ), $css_code ); } return $css_code; } protected function resolve_css_selector( string $markup_id ): string { $bem_name = $this->get_bem_name(); return $this->has_unique_bem_name() ? sprintf( '.%s', $bem_name ) : sprintf( '.%s--id--%s', $bem_name, $markup_id ); } /** * @return array */ public function get_common_mount_points(): array { $common_mount_points = array(); foreach ( $this->mount_points as $mount_point ) { // both into one array, as IDs and postTypes are different and can't be mixed up. $common_mount_points = array_merge( $common_mount_points, $mount_point->post_types ); $common_mount_points = array_merge( $common_mount_points, $mount_point->posts ); } return array_values( array_unique( $common_mount_points ) ); } /** * @return array */ public function get_exposed_post_fields(): array { return array( 'post_excerpt' => join( ',', $this->get_common_mount_points() ), 'post_content_filtered' => join( ',', $this->get_used_meta_group_ids() ), 'post_title' => $this->title, 'post_name' => $this->get_unique_id(), ); } /** * @param array $postFields * * @throws Exception */ // @phpcs:ignore public function saveToPostContent( array $postFields = array(), bool $isSkipDefaults = false ): bool { $post_fields = $this->get_exposed_post_fields(); // skipDefaults. We won't need to save default values to the DB. // @phpstan-ignore-next-line $result = parent::saveToPostContent( $post_fields, true ); // we made a direct WP query, which means we need to clean the cache, // to make the changes available in the WP cache. clean_post_cache( (int) $this->getSource() ); return $result; } /** * @param bool $is_without_prefix Set to true, when need short (abc3 in case of view_abc3) * * @return string */ public function get_unique_id( bool $is_without_prefix = false ): string { return ! $is_without_prefix ? $this->unique_id : explode( '_', $this->unique_id )[1] ?? ''; } public function get_post_id(): int { return (int) $this->getSource(); } // safe for json-only items. public function get_edit_post_link( string $context = 'display' ): string { $post_id = $this->get_post_id(); return 0 !== $post_id ? (string) get_edit_post_link( $post_id, $context ) : admin_url( sprintf( 'edit.php?post_type=acf_%ss&post_status=%s', $this->get_type(), Fs_Only_Tab::NAME ) ); } public function get_type(): string { return explode( '_', $this->get_unique_id() )[0]; } public function get_markup_id(): string { return ! $this->is_markup_with_digital_id ? $this->get_unique_id( true ) : (string) $this->getSource(); } public function get_markup(): string { $custom_markup = trim( $this->custom_markup ); return '' !== $custom_markup ? $custom_markup : $this->markup; } public function is_css_internal(): bool { return $this->is_with_shadow_dom() && false === strpos( $this->get_markup(), '' ); } public function get_js_code(): string { return $this->js_code; } public function is_web_component(): bool { return self::WEB_COMPONENT_NONE !== $this->web_component; } public function is_with_shadow_dom(): bool { return in_array( $this->web_component, array( self::WEB_COMPONENT_SHADOW_DOM_DECLARATIVE, self::WEB_COMPONENT_SHADOW_DOM ), true ); } public function get_tag_name( string $prefix = '' ): string { if ( $this->is_web_component() ) { return $this->get_web_component_tag_name( $prefix ); } return 'section'; } public function has_custom_markup(): bool { $custom_markup = trim( $this->custom_markup ); return strlen( $custom_markup ) > 0; } public function is_wp_interactivity_in_use(): bool { $markup = trim( $this->custom_markup ); $markup = '' === $markup ? $this->markup : $markup; return false !== strpos( $markup, 'data-wp-interactive' ); } /** * @return array{css:string,js:string,html:string} */ public function get_code_hashes(): array { if ( null === $this->hashes ) { $markup = '' !== $this->custom_markup ? $this->custom_markup : $this->markup; $this->hashes = array( self::HASH_CSS => hash( 'md5', $this->css_code ), self::HASH_JS => hash( 'md5', $this->js_code ), self::HASH_HTML => hash( 'md5', $markup ), ); } return $this->hashes; } protected function get_web_component_tag_name( string $prefix ): string { $has_unique_bem_name = $this->has_unique_bem_name(); $prepared_bem_name = str_replace( '_', '-', $this->bem_name ); $prepared_prefix = strlen( $prepared_bem_name ) > 0 ? $prepared_bem_name : $prefix; $is_dashed_bem_name = false !== strpos( $prepared_bem_name, '-' ); // WebComponent requires unique name AND at least one dash in it. return ( $has_unique_bem_name && $is_dashed_bem_name ) ? $prepared_bem_name : sprintf( '%s-%s', $prepared_prefix, $this->get_unique_id( true ) ); } public function get_classes_generation(): string { return $this->classes_generation; } public function get_template_engine(): string { return $this->template_engine; } public function get_controller_template_engine(): string { return PHP_Template_Engine::NAME; } public function get_sass_code(): string { return $this->sass_code; } public function get_ts_code(): string { return $this->ts_code; } public function get_web_component_type(): string { return $this->web_component; } }