|
6 | 6 | use Illuminate\Foundation\Bus\DispatchesJobs;
|
7 | 7 | use Illuminate\Http\Request;
|
8 | 8 | use Illuminate\Support\Facades\File;
|
| 9 | +use Illuminate\Filesystem\Filesystem; |
9 | 10 |
|
10 | 11 | class RenderLanguageSwitcher
|
11 | 12 | {
|
@@ -50,22 +51,25 @@ public function handle(
|
50 | 51 | $prefered_url = url()->locale($current_path,$prefered_locale); // Get the current url with the prefered locale
|
51 | 52 | $toggle_title = $this->toggle_title ? $this->toggle_title : $current_locale . " <span class='caret'></span>"; // If the user has passed a button title set it, else default to the currently enabled locale.
|
52 | 53 | $custom_title = $this->toggle_title != false; // Check if the user has set a custom title. Used in building the ul of locales
|
53 |
| - $composer_folder = '../core/wirelab/language_switcher-plugin/resources/views'; // The location of the views if the user installed the plugin using composer |
54 |
| - $manual_folder = File::directories('../addons')[0] . '/wirelab/language_switcher-plugin/resources/views'; // The location of the views if the user installed the plugin manually |
| 54 | + $filesystem = new Filesystem; |
| 55 | + $composer_folder = base_path() . '/core/wirelab/language_switcher-plugin/resources/views'; // The location of the views if the user installed the plugin using composer |
| 56 | + $manual_folder = base_path() . '/addons/' . env('APPLICATION_REFERENCE') . '/wirelab/language_switcher-plugin/resources/views'; // The location of the views if the user installed the plugin manually |
| 57 | + $published_folder = base_path() . '/resources' . env('APPLICATION_REFERENCE') . 'addons/wirelab/language_switcher-plugin/views'; // The locations of the views if the user published the views |
55 | 58 |
|
56 | 59 | // Try to find the views folder
|
57 |
| - if (file_exists($manual_folder)) { |
| 60 | + if ($filesystem->exists($published_folder)) { |
| 61 | + $views_dir = published_folder; |
| 62 | + } elseif ($filesystem->exists($manual_folder)) { |
58 | 63 | $views_dir = $manual_folder;
|
59 |
| - } elseif(file_exists($composer_folder )) { |
| 64 | + } elseif($filesystem->exists($composer_folder )) { |
60 | 65 | $views_dir = $composer_folder;
|
61 | 66 | } else {
|
62 | 67 | // If we can't find it throw a new exception
|
63 |
| - throw new Exception("Couldn't find view folder."); |
| 68 | + throw new Exception("[language_switcher-plugin] Couldn't find view folder."); |
64 | 69 | }
|
65 |
| - |
66 |
| - foreach (File::allFiles($views_dir) as $file){ |
67 |
| - // Use the names of the views as types |
68 |
| - $types[] = $file->getBaseName('.' . $file->getExtension()); |
| 70 | + foreach ($filesystem->allFiles($views_dir) as $file){ |
| 71 | + // Use the names of the views as networks |
| 72 | + types[] = $file->getBaseName('.' . $file->getExtension()); |
69 | 73 | }
|
70 | 74 |
|
71 | 75 | if (!in_array($type, $types)) {
|
|
0 commit comments