get_id() ) ); } if ( $task instanceof Post_Type_Task_Interface ) { continue; } $tasks_with_id[ $task->get_id() ] = $task; } $this->tasks = $tasks_with_id; } /** * Sets the tracking link adapter. * * @required * * @codeCoverageIgnore - Is handled by DI-container. * * @param Tracking_Link_Adapter $tracking_link_adapter The tracking link adapter. * * @return void */ public function set_tracking_link_adapter( Tracking_Link_Adapter $tracking_link_adapter ) { $this->tracking_link_adapter = $tracking_link_adapter; } /** * Gets a task. * * @param string $task_id The task ID. * * @return Task_Interface The given task. */ public function get_task( string $task_id ): ?Task_Interface { $all_tasks = $this->get_tasks(); return ( $all_tasks[ $task_id ] ?? null ); } /** * Gets a completeable task. * * @param string $task_id The task ID. * * @return Task_Interface The given task. */ public function get_completeable_task( string $task_id ): ?Completeable_Task_Interface { $all_tasks = $this->get_tasks(); $task = ( $all_tasks[ $task_id ] ?? null ); if ( ! $task instanceof Completeable_Task_Interface ) { return null; } return $task; } /** * Gets the tasks. * * @return array> The tasks. * * @throws Invalid_Tasks_Exception If an invalid task is added. */ public function get_tasks(): array { /** * Filter: 'wpseo_task_list_tasks' - Allows adding more tasks to the task list. * * @param array> $tasks The tasks for the task list. */ $tasks = \apply_filters( 'wpseo_task_list_tasks', $this->tasks ); $extra_tasks = []; foreach ( $tasks as $task_id => $task ) { if ( ! $task instanceof Task_Interface ) { throw new Invalid_Tasks_Exception(); } if ( $task->is_valid() === false ) { unset( $tasks[ $task_id ] ); continue; } // Generate child tasks for parent tasks. if ( $task instanceof Parent_Task_Interface ) { \array_push( $extra_tasks, ...$task->generate_child_tasks() ); } } return \array_merge( $tasks, $extra_tasks ); } /** * Gets the tasks data. * * @return array> The tasks data. */ public function get_tasks_data(): array { $tasks = $this->get_tasks(); $tasks_data = []; foreach ( $tasks as $task ) { // We need to enhance the links of the CTA first, if that exists. if ( $task->get_call_to_action() !== null ) { $task->set_enhanced_call_to_action( new Call_To_Action_Entry( $task->get_call_to_action()->get_label(), $task->get_call_to_action()->get_type(), $this->tracking_link_adapter->create_tracking_link_for_tasks( $task->get_call_to_action()->get_href(), ), ), ); } $tasks_data[ $task->get_id() ] = $task->to_array(); } return $tasks_data; } }