adminTexts = $adminTexts; } /** * Registers or Unregisters an option for translation depending * on the `state` data. * * @param Collection $data * * @return Either */ public function run( Collection $data ) { $state = $data->get( 'state' ) ? 'on' : ''; $applyState = partial( [ self::class, 'flatToHierarchical' ], $state ); $register = pipe( 'wpml_collect', Fns::map( $applyState ), Fns::reduce( 'array_replace_recursive', [] ), [ $this->adminTexts, 'icl_register_admin_options' ] ); $register( $data->get( 'selected', [] ) ); return Either::right( true ); } /** * string $state -> string [key1][key2][name] -> array [ key1 => [ key2 => [ name => $state ] ] ] * * @param string $state * @param string $option * * @return array */ public static function flatToHierarchical( $state, $option ) { // string $value -> mixed $key -> array [ $key => $value ] $makeArrayWithStringKey = function ( $value, $key ) { return [ (string) $key => $value ]; }; return \WPML_Admin_Texts::getKeysParts( $option ) ->reverse() ->reduce( $makeArrayWithStringKey, $state ); } }