Skip to content

Commit

Permalink
Add the Launchpad task body
Browse files Browse the repository at this point in the history
  • Loading branch information
Valter Lorran committed Oct 30, 2023
1 parent 4a7418e commit 10edac1
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

Adds basic functionality for adding body to the tasks. This will allow us for example to add text or buttons to the task.
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,11 @@ private function build_task( $task ) {
}
}

$extended_content = $this->load_extended_content( $task );
if ( $extended_content ) {
$built_task['extended_content'] = $extended_content;
}

return $built_task;
}

Expand Down Expand Up @@ -445,6 +450,38 @@ private function load_subtitle( $task ) {
return '';
}

/**
* Loads the extended content for a task.
*
* @param Task $task A task definition.
* @return array|null The extended content for the task.
*/
private function load_extended_content( $task ) {
if ( ! isset( $task['extended_content'] ) ) {
return null;
}

$extended_content_context = array();

foreach ( $task['extended_content'] as $context => $extended_content ) {
$loaded_extended_context = array();

$actions = $this->load_value_from_callback( $extended_content, 'actions', null, $task['id'] );
if ( $actions ) {
$loaded_extended_context['actions'] = $actions;
}

$content = $this->load_value_from_callback( $extended_content, 'content', null, $task['id'] );
if ( $actions ) {
$loaded_extended_context['content'] = $content;
}

$extended_content_context[ $context ] = $loaded_extended_context;
}

return $extended_content_context;
}

/**
* Loads the repetition count for a task, calling the callback if it exists.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ function wpcom_launchpad_get_task_definitions() {
// that are not in the Customer Home page. We should find a better way to handle this.
return '/domains/add/' . $data['site_slug_encoded'] . '?from=my-home';
},
'extended_content' => array(
wpcom_launchpad_add_task_extended_context( array( 'launchpad-navigator' ) ),
),
),

'share_site' => array(
Expand Down Expand Up @@ -1895,3 +1898,72 @@ function wpcom_launchpad_mark_theme_selected_complete( $new_theme, $old_theme )
wpcom_mark_launchpad_task_complete( 'site_theme_selected' );
}
add_action( 'jetpack_sync_current_theme_support', 'wpcom_launchpad_mark_theme_selected_complete', 10, 2 );

/**
* Adds a task component.
*
* @param string $type The type of the component ('text' or 'link').
* @param string $content The content of the component.
* @param array $options Additional options for the component (optional).
* @return array The task component.
*/
function wpcom_launchpad_add_task_component( $type, $content, $options = array() ) {
// Add validation and sanitization checks if necessary.

return array(
'type' => $type,
'content' => $content,
'options' => $options,
);
}

/**
* Adds a link task action.
*
* @param string $label The label (text) of the link.
* @param string $href The URL of the link.
* @return array The link task component.
*/
function wpcom_launchpad_task_action_link( $label, $href ) {
return wpcom_launchpad_add_task_component( 'link', $label, array( 'href' => $href ) );
}

/**
* Adds the extended context for a task.
*
* @param string $contexts The contexts in which the task should be shown.
* @param string $actions_callback The callback to use for the task actions.
* @param string $content_callback The callback to use for the task content.
* @return array The extended context.
*/
function wpcom_launchpad_add_task_extended_context( $contexts, $actions_callback = 'wpcom_launchpad_customize_task_actions', $content_callback = 'wpcom_launchpad_customize_task_content' ) {
return array(
'contexts' => $contexts,
'actions' => $actions_callback,
'content' => $content_callback,
);
}

/**
* Adds custom actions to tasks.
*
* @param array $extended_content The extended content for the task.
* @param array|null $default The default array with actions for the task.
* @param string $task_id The task ID.
* @return array The array with actions for the task.
*/
function wpcom_launchpad_customize_task_actions( $extended_content, $default, $task_id ) {
return apply_filters( 'wpcom_launchpad_customize_task_actions', null, $task_id );
}

/**
* Adds custom content to tasks.
*
* @param array $extended_content The extended content for the task.
* @param array|null $default The default array with actions for the task.
* @param string $task_id The task ID.
* @return string The content for the task.
*/
function wpcom_launchpad_customize_task_content( $extended_content, $default, $task_id ) {
return apply_filters( 'wpcom_launchpad_customize_task_content', null, $task_id );
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: changed
Comment: Updated composer.lock.


0 comments on commit 10edac1

Please sign in to comment.