I was solving the problem statement https://github.com/Dineshkushwaha/sph-test/blob/main/README.md and the challenge here is to not use any Contributed module.
I have Created a Hard-coded QR code Block and below is code of that Block:
public function build() { $path = ''; $directory = "public://Images/QrCodes/"; //prepareDirectory()($directory, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY); Drupal::service('file_system')->prepareDirectory($directory, DrupalCoreFileFileSystemInterface::CREATE_DIRECTORY); // Name of the generated image. $qrName = 'myQrcode'; $uri = $directory . 'QR'. '.png'; // Generates a png image. $path = Drupal::service('file_system')->realpath($uri); // Generate QR code image. PHPQRCodeQRcode::png("www.google.com", $path, 'L', 4, 2); $relative_file_url = Drupal::service('file_url_generator') ->generateAbsoluteString($uri); $qr_image = "<img src='{$relative_file_url}'/>"; return [ '#markup' => $qr_image, ]; }
The only issue is that I am not able to find logic to add the block on node and that too with dynamic QR code.
So Each node will have a unique QR Code Block. Please Help