Same logic as https://www.drupal.org/node/2800319#comment-11625805. info if unused, error if used.

We also need to check that demo only creates social share plugin thingies if the libraries are there.

Comments

Berdir created an issue. See original summary.

johnchque’s picture

Assigned: Unassigned » johnchque

Let's try this.

johnchque’s picture

StatusFileSize
new2.44 KB

Is there actually a way to disable the Social share privacy plugin? Or we should just check if it is used?

berdir’s picture

Check if there are config entities that have it selected, should be easy with an entity query.

johnchque’s picture

Status: Active » Needs review
StatusFileSize
new2.57 KB
new2.26 KB

Better like this. Wondering how I should make demo check if the libraries are there or not.

Status: Needs review » Needs work

The last submitted patch, 5: hook_requirements-2800473-5.patch, failed testing.

tduong’s picture

Wondering how I should make demo check if the libraries are there or not.

Not sure what is the problem, but you are checking the library already in Share Message core here and from is_file() API

@return bool true if the filename exists and is a regular file, false otherwise.

Otherwise for example in dropzonejs_requirements() they use libraries_get_path() but it is highlighted for me, I guess I need to install something more since PhpStorm complains about not finding that function in "build-in library and project files".

berdir’s picture

I think you can get the libraries definition yes and then if it is defined and has the library file then you can assume it is there. which won't be the case since demo doesn't depend on libraries I think?

also hardcoding that path is definitely wrong, that's what the libraries module is for, which should be used to find that path for us.

johnchque’s picture

Status: Needs work » Needs review
StatusFileSize
new2.7 KB
new682 bytes

Added libraries_get_path.

Status: Needs review » Needs work

The last submitted patch, 9: hook_requirements-2800473-9.patch, failed testing.

johnchque’s picture

Status: Needs work » Needs review

Unrelated test fail.

The last submitted patch, 3: hook_requirements-2800473-3.patch, failed testing.

berdir’s picture

Status: Needs review » Needs work
+++ b/sharemessage.install
@@ -52,20 +52,31 @@ function sharemessage_requirements($phase) {
+    if (\Drupal::moduleHandler()->moduleExists('libraries')) {
+      $directory = libraries_get_path('socialshareprivacy');
+    };
+    $has_social_share = is_file($directory . '/jquery.socialshareprivacy.min.js');

this makes no sense if $directory is an empty string, you'd look for this file in the top drupal folder.

The whole check can only be done if libraries.module is installed.

However, there clearly is more wrong here. We need to have something clean before we can continue here.

Have a look at the sharre integration, with hook_libraries_info() and hook_library_info_alter(). socialshareprivacy must work in the same way, so that you can for example move the files to sites/all/libraries and it will still work.

Once we have that, we can continue with the requirements hook, which we should do for sharre as well. I'm fine with cleaning up here, but we could also postpone on another issue first.

johnchque’s picture

Status: Needs work » Postponed
Related issues: +#2825770: Improve libraries hook of Socialshareprivacy plugin

Postponed until the related issue gets in.

johnchque’s picture

Status: Postponed » Needs work

Back to needs work since the related issue got in.

miro_dietiker’s picture

Component: Code » Plugins
miro_dietiker’s picture

tbonomelli’s picture

Maybe we should change the requirements description to something like this:
The <a href=":url">Social Share Privacy library</a> should be installed at <strong>/libraries/socialshareprivacy/jquery.socialshareprivacy.min.js.</strong> Additionally, you need to download the "jquery.socialshareprivacy.min.js" and the "jquery.socialshareprivacy.min.css" files separately. Copy the js file into the "socialshareprivacy" and the css file into the "socialshareprivacy/stylesheets" directory.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new2.99 KB
new3.17 KB

I'm more and more confused about how we integrate this.

The file structure we have seems pretty made up. the files exist, but you can't just download them like that from anywhere, but have to download the single files and put them together. And the library is pretty old and hasn't been updated in 2years.

There's another version here https://github.com/patrickheck/socialshareprivacy, fewer forks/likes, but is available as a bower library.

Here's a patch that works, but we need to discuss about what we want to do with this exactly. Was hoping to do release once this is fixed but not sure right now.

  • Berdir committed 34ed830 on 8.x-1.x
    Issue #2800473 by yongt9412, Berdir: hook_requirements() should only be...
berdir’s picture

Status: Needs review » Fixed

Committed, this is definitely an improvement already and doesn't make anything worse.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.