fields = new Fields( $provenance ); $this->views = new Views(); add_filter( self::FILTER, [ $this, 'contribute' ], 10, 2 ); } /** * Add our fields and views to the Pages screen configuration. * * @param \WP_View_Config_Data $data The configuration container. * @param array $entity The entity being configured. * @return \WP_View_Config_Data */ public function contribute( $data, $entity = [] ) { if ( ! is_object( $data ) || ! method_exists( $data, 'merge' ) ) { return $data; } $patch = $this->patch(); if ( empty( $patch ) ) { return $data; } $data->merge( $patch, self::SCHEMA_VERSION ); return $data; } /** * The patch itself, built separately so it can be asserted without a host. * * Note what is NOT here: no `sort`, no `layout`, no wholesale `fields` * replacement, and no removal or reordering of the host's own views. Those * absences are the requirement (FR-008), which is why this method is the * unit under test rather than the rendered screen. * * @return array Empty when there is nothing to contribute. */ public function patch(): array { $views = $this->views->definitions(); if ( empty( $views ) ) { // No Templately content on this site: contribute nothing at all, so // the screen is indistinguishable from a site without the plugin // (FR-011, SC-004). return []; } return [ 'default_view' => [ 'fields' => $this->fields->ids(), ], 'view_list' => $views, ]; } }